• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Guru: Speed Up Command-Line PHP

    January 21, 2019 Alan Seiden

    While PHP runs quickly via the Apache web server, command-line PHP scripts (run from PASE directly or via CL or RPG) have a lag on start-up. In this article, I show how to speed up PHP when called from the command line (known as PHP-CLI).

    Why does PHP-CLI (command line PHP) have a slow start-up? While several reasons are often given, I’ve found the culprit to be the loading of PHP extensions that are enabled by php.ini and other configuration files of Zend Server. Examples of extensions are ibm_db2, simplexml, and Zend’s proprietary components.

    Within a normal web server environment, loading extensions doesn’t slow down PHP, because FastCGI preloads all configured extensions when it preloads PHP. On the other hand, when you run PHP from a command line (or from CL or RPG), PHP can’t be pre-loaded; it’s loaded at runtime. In that case, several seconds may be required to load extensions.

    You can use the –no-php-ini and –define options to speed up PHP-CLI. Here’s a quick reference from http://php.net/manual/en/features.commandline.options.php:

    –no-php-ini Ignore php.ini completely.
    –define Set a custom value for any of the configuration directives allowed in php.ini.

    Note that all examples below assume PHP 7, which is installed in /usr/local/zendphp7, but you could substitute any valid recent PHP version or location.

    Let’s consider a simple script:

    <?php
    
    // simple.php code
    
    echo "PHP script running.\n";
    
    ?>
    

    Simple.php outputs a message to show that it is running. Because we wish to measure the overhead of running a script, not the time required by the script itself, a simple script is best. Save simple.php somewhere on your IFS. Ensure that your user profile has *R permissions and all directories above it have at least *X. For our example, let’s save it in /www/zendphp7/htdocs, although it could go anywhere.

    Run simple.php

    First, go into a PASE terminal. (An SSH shell with Bash would work better, but I realize that you may not have Bash installed, so I’ll demonstrate using traditional QP2TERM.)

    CALL PGM(QP2term)
    

    Now let’s go to the directory of the PHP 7 binary:

    cd /usr/local/zendphp7/bin
    

    Run the speed test using the default php.ini:

    php /www/zendphp7/htdocs/simple.php
    

    If you used a stopwatch, you’d notice that the test needed up to a couple of seconds to run, even though the script did virtually nothing.

    Now add –no-php-ini, which prevents PHP from reading any .ini file, and thus not loading any extensions.

    php --no-php-ini /www/zendphp7/htdocs/simple.php
    

    Using the –no-php-ini option, you’ll observe that the script returned almost immediately.

    Our choices aren’t “all or nothing.” We can add configuration values on the command line.

    Run our test script again, this time adding –define to load the ibm_db2 extension, a commonly used extension for IBM i.

    php --no-php-ini --define extension=/usr/local/zendphp7/lib/php_extensions/ibm_db2.so /www/zendphp7/htdocs/simple.php
    

    The script still ran quickly with a single extension loaded.

    Speed at your command

    I have demonstrated that PHP-CLI runs substantially faster when we cut back on extensions, using PHP’s –no-php-ini and –define options. Try this technique and enjoy the improvement.

    An IBM Champion and founder of Seiden Group, Alan Seiden leads a team that mentors clients in building APIs and web/mobile applications using open source, PHP, Python, Node.js, and IBM i business logic. Alan’s passion for the IBM i community inspires him to host the bi-annual CIO Summit and offer a free monthly tips newsletter.

    RELATED STORY

    Custom PHP CLI php.ini configuration on #IBMi

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: CL, FHG, Four Hundred Guru, PHP, PHP-CLI, RPG

    Sponsored by
    PERFSCAN

    Revolutionary Performance Management Software

    At Greymine, we recognize there is a void in the IT world for a dedicated performance management company and also for a performance management tool that’s modern, easy to use, and doesn’t cost an arm and a leg. That’s why we created PERFSCAN.

    PERFSCAN is designed to make your job easier. With revolutionary technology, an easy-to-read report and graphics engine, and real time monitoring, tasks that used to take days can now take minutes. This means you will know your system better and will be able to provide better service to your customers.

    OUR FEATURES

    PERFSCAN is full of robust features that don’t require you to take a three-day class in order to use the product effectively.

    Customizable Performance Reporting

    Whether you are troubleshooting a major system problem or simply creating a monthly report, PERFSCAN lets you select any combination of desired performance metrics (CPU, Disk, and Memory).

    User Defined Performance Guidelines

    No matter if you are a managed service provider managing complex systems in the cloud or a customer analyzing your on-premises solution, PERFSCAN gives you the flexibility to define all mission critical guidelines how they need to be.

    Understanding The Impact Of Change

    Tired of all the finger pointing when performance is suffering? PERFSCAN’s innovative What’s Changed and Period vs. Period analysis creates a culture of proof by correlating known environmental changes with system performance metrics.

    Comprehensive Executive Summary

    Creating performance graphs is easy. Understanding what they mean is another thing. With one mouse click, PERFSCAN includes an easy-to-understand executive summary for each core metric analyzed.

    Combined Real-Time Monitor And Performance Analysis Tool

    With PERFSCAN’s combined built in enterprise real-time monitor and historical performance analysis capability, you will always know how your mission-critical systems are performing.

    Cloud Performance Reporting Is Easy

    Managing performance for production systems in the cloud can be a black hole to many system administrators. The good news is PERFSCAN analyzes all core metrics regardless of the location. That’s why MSPs and customers love PERFSCAN.

    Detailed Job Analysis

    PERFSCAN shows detailed top job analysis for any desired period. All metrics are displayed in two ways: Traditional Report and Percentage Breakdown Pie Chart. This toggle capability instantly shows the jobs using the most system resources.

    Save Report Capability

    Your boss lost the report you gave to him on Friday. Now what do you do? With PERFSCAN’s save report capability, any report can be retrieved in a matter of seconds.

    Professional PDF Reporting With Branding

    Creating professional looking reports for your customers has never been easier with PERFSCAN. Branding for our partners and service provider customers is easy with PERFSCAN.

    Check it out at perfscan.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    As I See It: The Challenge To Selfhood Infor Raises $1.5 Billion, Teases An IPO

    2 thoughts on “Guru: Speed Up Command-Line PHP”

    • Martin Hieden says:
      January 24, 2019 at 2:22 am

      Hello Alan,
      Maybe it’s also worth to mention that you can use the –php-ini option to start PHP from command line using a separate ini-file. This comes in especially handy when you have multiple CLI calls, which all use the same configuration.
      Best Martin

      Reply
      • alanseiden says:
        January 31, 2019 at 10:54 pm

        Thanks, Martin! You make an excellent point about –php-ini. I plan to write a second article about PHP-CLI, demonstrating –php-ini and how to use multiple –define options.
        Alan

        Reply

    Leave a Reply Cancel reply

TFH Volume: 29 Issue: 4

This Issue Sponsored By

  • Maxava
  • ProData Computer Services
  • WorksRight Software
  • Dawn May Consulting
  • Manta Technologies

Table of Contents

  • The IBM i Base Did Indeed Move On Up
  • Infor Raises $1.5 Billion, Teases An IPO
  • Guru: Speed Up Command-Line PHP
  • As I See It: The Challenge To Selfhood
  • IBM i PTF Guide, Volume 21, Number 2

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • IBM i Delivers Sizable Benefits, Forrester Consulting Reports
  • SBOMs Will Come to IBM i, Eventually
  • IBM i Backup Provider Storagepipe Snapped Up By Thrive
  • Four Hundred Monitor, June 7
  • IBM i PTF Guide, Volume 25, Number 23
  • Power10 Boosts NVM-Express Flash Performance
  • Fortra Completes Postmortem Of GoAnywhere Vulnerability
  • Guru: Binding Directory Entries
  • How Does Your Infrastructure Spending Stack Up To The World?
  • IBM i PTF Guide, Volume 25, Number 22

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2023 IT Jungle