0

Am trying to increase script execution time for a curl request in php for uploading a very large files.

I Can set the curl timeout as follows

curl_setopt($ch, CURLOPT_TIMEOUT, 300);

Now I need to ensure that php script does not timeout as well. Am confused on the approached to be implemented irrespective of whether the server is running Apache or Nginx or IIS etc.

Some articles suggest that max_execution_time is good since it uses ini_set() and that you can gets its results using init_get() while some scholars suggest the use set_time_limit saying that max_execution_time is only to be used when running apache.

Am really confused as my coconut head keeps cracking. Any suggestions on the best way to go will be appreciated

1.) Am I to use max_execution_time or set_time_limit or should I use both

ini_set('max_execution_time', 300); // 5 miutes
set_time_limit(300);

2.)Again In which scenario is max_execution_time preferable over set_time_limit and vice versa.

Henrymart
  • 122
  • 1
  • 9

1 Answers1

2

I found out that my hosting company set their default timeout for sending each request so no matter how one tends to increase the max_execution timeout, its still ineffective.

I now realize that the best option is to use

set_time_limit(28) within the main while loop so each loop iteration of chunked file is limited to 28 seconds as opposed to setting it to the whole script.

something like this is what I did

while(){
set_time_limit(28);
//process your chunked data here on each loop


}
Henrymart
  • 122
  • 1
  • 9