PHP configuration

PHP can vary between OS distributions; see the documentation specific to your installation of PHP.

  1. First determine which PHP .ini file is in use by the PHP Apache module.

    The php.ini used by your web server may differ from the one used by the command-line interface. Running php --ini only shows the CLI configuration.

    If you are having trouble determining which .ini file the PHP Apache module is using, create a PHP file that can be served through Apache with the following contents:

    <?php phpinfo();?>

    Point your browser to this file and look for this table row in the resulting table:

    Loaded Configuration File

  2. Open the php.ini configuration file and increase the memory_limit to 512M, default value is 256M.

    Large changelists may fail to submit if the memory_limit is too low.

    An example memory_limit setting in php.ini:

    memory_limit = 512M

    If you are still having memory limitation issues, see Troubleshooting out of memory (OOM) issues

  3. Ensure that date.timezone is set correctly for your system.

    Some distributions do not make a default timezone available to PHP, so the best practice to set the timezone for PHP explicitly. See the list of supported timezones.

    An example date.timezone setting in php.ini:

    date.timezone = America/Vancouver

  4. Verify that the iconv, json, and session extensions are present.

    They are usually enabled by default, although you may have to install packages for them through your OS distribution. Verify they are present by searching for their respective names in the phpinfo output above.

  5. Enable P4 API for PHP, the Perforce extension for PHP:

    For P4 Code Review to communicate with the P4 Server, it needs the P4 API for PHP extension. P4 API for PHP variants are available for each PHP 8 version supported by P4 Code Review and each variant is available as either openssl 1.02 or openssl 1.1.1. All of the P4 API for PHP variants are supplied with the P4 Code Review package and tarball installations.

    • For Linux, the default variants are compiled with glibc 2.11.
    • P4 API for PHP 2019.1 or later is required for P4 Code Review 2019.1 and later.
    • P4 Code Review package and tarball installations: two versions of P4 API for PHP are supplied for PHP 8 version supported by P4 Code Review. They are located in the p4-bin/bin.linux26x86_64 directory.

      • perforce-php8x.so compatible with systems using SSL 1.0.2
      • perforce-php8x-ssl1.1.1.so compatible with systems using SSL 1.1.1
      • perforce-php8x-ssl3.so compatible with systems using SSL 3.0.0 (by default, Ubuntu 22.04 and 24.04 uses SSL 3.0.0)

      Where x is the version of PHP 8.

      P4 Code Review no longer supports PHP 8.0 version.

      If the perforce.ini file is not pointing at the correct version of P4 API for PHP and you connect to an SSL enabled P4 Server:

      • The P4 Code Review web-page will not load and you might see a Connection Reset error.
      • There might be an undefined symbol: SSLeay message in the Apache error log

    To enable P4 API for PHP, edit the web server's php.ini file and add the following line:

    extension=/path/to/swarm/p4-bin/bin.<platform>/perforce-<php8.x><ssl>.so

    Replace <php8.x> with the version of PHP 8 you are running.

    P4 Code Review no longer supports PHP 8.0 version.

    Supported versions of PHP 8 are as follows:

    • For PHP 8.1, use php81

    • For PHP 8.2, use php82

    • For PHP 8.3, use php83

    • For PHP 8.4, use php84

    Replace <ssl> with the variant of openssl your system is running. Enter the following into <ssl> for the variant of openssl you are running:

    • For SSL 1.0.2, you do not need to enter a variant. See Example 1 below.

    • For SSL 1.1.1, use ssl1.1.1

    • For SSL 3.0.0, use ssl3

    See the examples below:

    Example 1: for a 64-bit Linux system running PHP 8.1 and SSL 1.0.2:

    extension=/path/to/swarm/p4-bin/bin.linux26x86_64/perforce-php81.so

    Example 2: for a 64-bit Linux system running PHP 8.3 and SSL 1.1.1:

    extension=/path/to/swarm/p4-bin/bin.linux26x86_64/perforce-php83-ssl1.1.1.so

    Example 3: for a 64-bit Linux system running PHP 8.4 and SSL 3.0.0:

    extension=/path/to/swarm/p4-bin/bin.linux26x86_64/perforce-php84-ssl3.so

    Alternatively, copy the extension file to the default location for PHP extensions, and then just add this line instead:

    extension=perforce-<php8.x><ssl>.so

  6. Restart Apache for the changes to become active.
  7. To verify that P4 API for PHP is active, navigate to the phpinfo file you created above. You should then see a perforce section (search for "Perforce Module"). It should report that the module is enabled and display the version information.
  8. Be aware that any operating system upgrades on the machine hosting P4 Code Review may involve updates to PHP. If this occurs, the PHP .ini file needs to be updated to point to the correct variant of P4 API for PHP to match the version of PHP that the upgraded operating system is using.

  9. In addition, P4 Code Review greatly benefits from the following optional extension: ImageMagick extension for PHP to improve P4 Code Review's ability to preview graphic formats that web browsers typically cannot display, see ImageMagick (imagick) extension for PHP.
  10. Configure P4 Code Review, see P4 Code Review configuration.

ImageMagick (imagick) extension for PHP

Imagick is a PHP extension that integrates the ImageMagick graphics library's API for the creation and manipulation of images. Enabling Imagick improves P4 Code Review's ability to preview graphics formats that web browsers typically cannot display and to create comment attachment thumbnails.

For more information, see:

Follow the instructions for your OS distribution:

RHEL and Rocky Linux

  1. We recommend that you install Imagick from your OS distribution, via yum, etc. If your distribution does not offer the imagick package for PHP, install it via PECL (although you may have to resolve system dependencies):

    sudo pecl install imagick

  2. Verify that imagick is enabled in your PHP Apache module's PHP .ini file (as determined in the section above for P4 API for PHP). You may need to add the following line:

    extension=imagick.so

  3. Configure the ImageMagick policy.xml file to allow P4 Code Review to create thumbnails if it is not already configured:

    1. Open the ImageMagick policy.xml file for editing:

    2. /etc/ImageMagick-6/policy.xml

    3. Disable lines with the pattern below for the following <filetype>s: PS, PS2, EPS, PDF, or XPS:

    4. <policy domain="coder" rights="none" pattern="<filetype>" />

    5. Save the policy.xml file.

  4. Restart Apache for the changes to become active.
  5. To verify that imagick is active, navigate to the phpinfo file you created earlier. You should then see an imagick section. It should report its version information and a table for its directives, supported image file formats, and more.

    Once you have completed installing and enabling P4 API for PHP and imagick, we recommend that you remove the phpinfo file you created to avoid disclosing information about your installation.

Ubuntu

  1. Install the generic php-imagick module.

    # sudo apt install php-imagick

  2. Or install a specific version.

    # php --version

    PHP 8.1.2-1ubuntu2.19 (cli) (built: Sep 30 2024 16:25:25) (NTS)

    # sudo apt install php8.1-imagick

  3. Restart Apache for the changes to become active.

    # sudo systemctl restart apache2

  4. To verify that imagick is active, navigate to the phpinfo file you created earlier. You should then see an imagick section. It should report its version information and a table for its directives, supported image file formats, and more.

    Once you have completed installing and enabling P4 API for PHP and imagick, we recommend that you remove the phpinfo file you created to avoid disclosing information about your installation.

Troubleshooting out of memory (OOM) issues

If you are running P4 Code Review servers running PHP 8.x on a RHEL platform, some PHP processes (called php-fpm threads) may get stuck or idle and fail to release memory. These are known as zombie or idle threads. Over time, these idle threads caused the server to run out of memory, sometimes crashing or requiring frequent restarts of the php-fpm service.

Workaround: Stop using php-fpm and instead run P4 Code Review with mod_php under Apache prefork MPM. To switch to mod_php, follow these steps:

  1. Edit the Apache MPM configuration:

    sudo nano /etc/httpd/conf.modules.d/00-mpm.conf
  2. Enable prefork MPM by uncommenting this line:

    LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
  3. Disable event MPM by commenting out this line:

    #LoadModule mpm_event_module modules/mod_mpm_event.so
  4. Restart Apache:

    sudo systemctl restart httpd
  5. Verify the active MPM:

    httpd -V | grep MPM

You will see the following if you have successfully switched to mod_php:

Server MPM: prefork