The maximum execution time limit helps prevent poorly written scripts from tying up the server. The execution time limits can live in different levels within your application stack and it's good practice keeping these limits as low as possible but depending on the nature of your application you may need to adjust them slightly.
In general, the best approach when dealing with long-running tasks is to isolate them from the webserver. For instance, you can achieve this by running PHP scripts over the command line when connected to the Container via SSH. The command would look like the below:
php /container/application/script.php
Developers often make use of cron to run tasks that need to be autonomously executed through the command line. Check out our Cron Jobs article if you wish to read more on this.
When running PHP scripts from the command line, no execution time limit is imposed by default. When scripts are executed through a webserver, the default max_execution_time
is 30 seconds. If you need to adjust this, you can edit the php.ini configuration file and restart the Container. For the default SiteHost Web Images this configuration file is located at the path /container/config/php/php.ini
Most default SiteHost Web Images have been built to take advantage of the FastCGI Process Manager (FPM) and because most web pages should return results in less than a minute, the default webserver proxy timeout is 60 seconds. If you need to adjust this, the configuration file location and directive that needs to be updated depends on the Container Image:
Webserver | Configuration file location | Directive |
---|---|---|
Apache | /container/config/apache2/sites-enabled/000-default.conf | ProxyTimeout |
Nginx | /container/config/nginx/sites-available/default | proxy_read_timeout and fastcgi_read_timeout |
It's worth noting any configuration changes would only apply after a Container reboot.
The SiteHost Cloud Containers have been designed with a Nginx reverse-proxy handling the incoming requests for all Containers on the server. As a result of this, to effectively raise the execution time limits with anything over 60 seconds, it is required to configure both the Container's webserver and the Nginx reverse-proxy. The Nginx reverse-proxy adjustments need to be performed by the SiteHost support team, so please get in touch with us if that's the case.