Warning: The magic method SFML_Singleton::__wakeup() must have public visibility in /home/public/wp-content/plugins/sf-move-login/inc/classes/class-sfml-singleton.php on line 72

Warning: Cannot modify header information - headers already sent by (output started at /home/public/wp-content/plugins/sf-move-login/inc/classes/class-sfml-singleton.php:72) in /home/public/wp-includes/feed-rss2.php on line 8
nginx – Thoughts, etc. https://www.munderwood.ca Tracking the occasional random walk Fri, 03 Mar 2017 19:21:47 +0000 en-CA hourly 1 https://wordpress.org/?v=5.7.2 https://www.munderwood.ca/wp-content/uploads/2016/03/photo-150x150.jpg nginx – Thoughts, etc. https://www.munderwood.ca 32 32 Long-running PHP process on nginx https://www.munderwood.ca/index.php/2016/12/13/long-running-php-process-on-nginx/ https://www.munderwood.ca/index.php/2016/12/13/long-running-php-process-on-nginx/#respond Wed, 14 Dec 2016 00:29:12 +0000 http://www.munderwood.ca/?p=141 [Read more...]]]> Recently I had to allow a PHP script to run for several minutes under Nginx (more specifically, as part of a Laravel app on a DigitalOcean server), after encountering the error “504 Gateway Timeout”. First, to tell Nginx to allow the script to run for a longer period of time, I set the FastCGI read timeout to ten minutes in  /etc/nginx/sites-available/default:

server {
    # … other directives
    location ~ \.php$ {
        # … other configuration
        fastcgi_read_timeout 600;
    }
}

Second, to increase the amount of time that this particular PHP routine could spend running, I increased the execution time limit programmatically before each processing block:

public function long_running_process ($blocks)
{
    foreach ($blocks as $block) {
        // Add to the total execution time for this script.
        set_time_limit(120);
        // Perform another block of data processing.
        $this->process_block($block);
    }
}

With this configuration, other PHP scripts are still capped at the default timeout value set in  php.ini, and no individual block of processing is allowed to run away with the full ten-minute time limit.

]]>
https://www.munderwood.ca/index.php/2016/12/13/long-running-php-process-on-nginx/feed/ 0