PHP-CLI has maximum execution time clamped at 300 seconds

adamreece.webbox

Active Member
Nov 3, 2016
38
12
8
Penarth, United Kingdom
cPanel Access Level
Root Administrator
Hi there,



When running CLI PHP scripts, such as the Symfony console binary, the execution time appears to be clamped at 300 seconds. Calling set_time_limit(), ini_set("max_execution_time"), or using the -d CLI option to override "max_execution_time" all make no difference. (Both increasing and decreasing.)

The cPanel account in question is configured to use FPM for PHP via HTTP, which has a 600 second execution limit working fine, but that doesn't apply to CLI execution. Scripts via HTTP can also change their execution time limit as expected.

PHP is installed via EasyApache 4. We're using version 7.2 for this account due to reasons.

Code:
$ which php-cli
alias php-cli='/opt/cpanel/ea-php72/root/usr/bin/php'
        /opt/cpanel/ea-php72/root/usr/bin/php

$ php-cli -v
PHP 7.2.32 (cli) (built: Jul 29 2020 17:34:57) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.32, Copyright (c) 1999-2018, by Zend Technologies

$ php-cli -i | grep max_execution_time
max_execution_time => 0 => 0
Calling echo ini_get("max_execution_time"); within the same CLI script shows the intended figure, but it still closes prematurely at the standard 300 second limit.

Where can we adjust this?

File /opt/cpanel/ea-php72/root/etc/php.ini specifies 600 seconds, though this seems to apply to just FPM.

Thanks. :)
 
Last edited:

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,304
1,250
313
Houston

adamreece.webbox

Active Member
Nov 3, 2016
38
12
8
Penarth, United Kingdom
cPanel Access Level
Root Administrator
Hi Lauren,

Thank you for your response. As per your request:

Code:
# rpm -qa | grep php-cli | sort
ea-php56-php-cli-5.6.40-15.15.1.cpanel.x86_64
ea-php71-php-cli-7.1.33-7.7.1.cpanel.x86_64
ea-php72-php-cli-7.2.32-2.2.1.cpanel.x86_64
ea-php73-php-cli-7.3.20-2.2.1.cpanel.x86_64
ea-php-cli-1.0.0-9.9.3.cpanel.x86_64
ea-php-cli-lsphp-1.0.0-9.9.3.cpanel.x86_64

# cat /etc/cpanel/ea4/php.conf
---
default: ea-php73
ea-php56: suphp
ea-php71: suphp
ea-php72: suphp
ea-php73: suphp
I'd not seen that documentation.

I think this is actually our mistake. The script in question is not a simple single file but class based with inheritance and such. At an earlier point a parent class was calling set_time_limit(300) before the primary class was calling set_time_limit(3600). Either a race condition was occurring whereby the parent class' call was happening after the primary class, or a bug in PHP doesn't accept any subsequent calls to set_time_limit() after the first. Either way I'm not very confident that cPanel or its PHP-CLI configuration is at fault, though perhaps our mistake and findings will be useful for someone else.
 
  • Like
Reactions: cPanelLauren