Impossible to increase max_execution_time for uploads from inside script

If you upload a large file, one of the more important php.ini settings is max_execution_time. To only change this setting for specific actions one could try to use set_time_limit() at the beginning of those actions that expect large $_POST data. But this will not work: The script will always time out, before the first line of code is run. So there’s no way to increase execution time from inside the script for large uploads.

Does anyone object to this? :) I just want to make sure i’m not overlooking something. So if someone disagrees, let me know.

One workaround i see, would be to use a .htaccess file with some php_value inside specific <Location> directives for the upload URL.

I think you should use max_input_time instead.

Yes, there are different settings that might need to be changed. Still it’s the same problem: You can’t change these settings inside your script, because that’s too late.

Yes, correct. The only one way to set these options is configuring php on HTTP server (permanent php.ini change or special case for location).

Why do you want to play with that instead of permanently setting things in php.ini?

This is especially in the context of what official PHP guide says about set_time_limit():

I don’t want this to affect all my scripts. Only those that really require e.g. more time for execution should get this privilege. There could be some error condition (e.g. problem with db connection) that causes lot of “zombie” processes to hang around for 300 seconds instead of killing them off soon after some short timeout. So i see this as one step in saving server ressources.

I see you point, Mike. I can be only sorry for you because I recall from my earlier projects (not too much in this area) that whenever script execution time problem appeared a really trouble were starting. Meaning that at least in my situation, using php.ini and functions related to script timeout never worked as supposed (see second point of this post as an example). I find myself this part of PHP the worst coded among all others! :(

Is there any specific way to allow unlimited time execution for a particular method?

I have a cron job method which will import the data into the database but every time it got an error 504 - Gateway Timeout

I have added code like this.

public function actionMethodName()
{
        set_time_limit(0);
	    ini_set("memory_limit", "-1");
	    ini_set("max_execution_time", "-1");}
        /* rest of the code */
}

But above code is not working.

How can I execute this method without any max time of execution?

Please note this method will called by CRON Job using URL

https://example.com/controller/method-name

Any suggestion would be appreciated.