Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zafercuz's avatar

Increasing max execution time in production not working

My project needs more than 60 seconds to query thousands of data. I placed ini_set('max_execution_time', 180); just after the namescape on my main controller. It somehow increased the execution time to 3 minutes but it only works in development stage. In production stage, it limits execution time to 60 seconds even though I've placed the code.

I've tried changing the max_execution_time to 180 in php.ini, then restarted php7.2-fpm, nginx, recaching the config of the project but still didn't work.

Is this a laravel thing? or a PHP thing? Because I've already tried changing both php.ini in both cli and fpm folder and restarted php7.2-fpm and nginx service, but it still doesn't work.

Update: Turned out it also didn't work in local server on nginx, which would probably mean it's nginx that's causing this problem. Any ideas as to why? Here's what my server config looks like

server {
    listen 80;
    server_name example.com;
    #root /var/www/Project_KamotV2/public;
    root /home/steven-sama/Project_KamotV2/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

I copied this from laravel official site in deployment section in the documentation.

0 likes
12 replies
douglasakula's avatar

Try run php --ini to confirm the loaded ini file is the one being edited.

zafercuz's avatar

@douglasakula when I ran that it locates to the cli folder, I then tried changing the php.ini and restarting the php service and nginx. Also changed the setting from the fpm folder but to no avail it still persist to 1 minute.

Why does it not just execute ini_set('max_execution_time', 180);? This problem only occurs on production.

douglasakula's avatar

@zafercuz - Just to be clear - you have full (reasonable) control of production server and it's not running in safe mode - right

zafercuz's avatar

@hondnl Since I'm using Nginx it is said that with nginx the php.ini is loaded from the fpm folder so I tried changing it there too. Ofc after changing it, I restarted php7.2-fpm and nginx. But to no avail it still doesn't work.

hondnl's avatar

Take a look at :

/etc/php/7.2/fpm/php-fpm.conf and /etc/php/7.2/fpm/pool.d/www.conf

see if request_terminate_timeout is uncommented....

Also in your nginx.conf take a look if there is fastcgi_read_timeout enabled.

Are you behind a load balancer ? The timeout may come from somewhere else then your php execution time.

zafercuz's avatar

@hondnl request_terminate_timeout is commented

and in nginx.conf there is no fastcgi_read_timeout

And server is not behind a load balancer too.

This is getting somewhat annoying to solve now :(

hondnl's avatar
hondnl
Best Answer
Level 5

echo phpinfo(); can you see the right execution time ? If so then the problem is not from the ini file. Since your dev is working correctly, there must be a setting in your production that is causing this.

Go through all possible timeout settings in nginx ( look it up) . Google your specific setup ( OS,caching anything else running) and timeout problems. There must be some setting wrong if it is not php.

Good luck!

1 like
zafercuz's avatar

Turned out this was caused by Nginx's configuration and not by PHP nor Laravel configuration. All I had to do was add two lines in /etc/nginx/nginx.conf in the http section

fastcgi_read_timeout 300;
proxy_read_timeout 300;

@hondnl Thanks bud, when you said timeout settings in nginx that was the clue to making this work, cheers!

Please or to participate in this conversation.