7

My PHP code is timing out with the following error:

This request takes too long to process, it is timed out by the server. If it should not be timed out, please contact administrator of this web site to increase 'Connection Timeout'

I'm not sure why this is happening. This is my code:

if(!in_array($name,$names)){
    mysql_query("INSERT INTO `tbl` (`name`, `time`, `link`) VALUES ( '$name', '$time', '$link');");
} else {
    mysql_query("UPDATE `tbl` SET `time` = '$time', `link` = '$link' WHERE `pishkhan`.`name` = $name;");
    echo $name.'<br/>'; 
}
file_put_contents('test/albums/news/'.$name.".jpg", fopen($link, 'r'));
Simon East
  • 55,742
  • 17
  • 139
  • 133
ttrasn
  • 4,322
  • 4
  • 26
  • 43
  • 1
    please state clearly what you want to achieve and what is currently happening!? – luk2302 Apr 14 '15 at 09:05
  • When i run this page for 132 process returned this error : This request takes too long to process, it is timed out by the server. If it should not be timed out, please contact administrator of this web site to increase 'Connection Timeout'. – ttrasn Apr 14 '15 at 09:07

4 Answers4

21

As I stated in my answer here, this particular error message is generated by the LiteSpeed web server (a faster replacement for Apache). It has a special feature whereby it cancels long-running scripts (even those that use set_time_limit()). To disable this, you need to put the following in your .htaccess file in the root of your site.

RewriteEngine On
RewriteRule .* - [E=noabort:1]
RewriteRule .* - [E=noconntimeout:1]
Simon East
  • 55,742
  • 17
  • 139
  • 133
  • My man, thank you! You saved my desk from my head. If anyone else stumbles across this, [here](https://docs.litespeedtech.com/lsws/cp/cpanel/long-run-script/) is some more information on the `noabort` and `noconntimeout` settings in Litespeed. – MrHunter Feb 17 '23 at 19:12
3

You can set set_time_limit to bigger value than default 30s. But from your code, I don't see why it must make timeout. Maybe some configuration issues? Like mysql is taking too long to connect?

Also, don't use deprecated mysql_* functions. Use mysqli_* or PDO.

Justinas
  • 41,402
  • 5
  • 66
  • 96
0

Sounds like your host limits execution time. Maybe have a look into setting the time limit before you run your loop? http://php.net/manual/en/function.set-time-limit.php

Nick
  • 2,803
  • 1
  • 39
  • 59
  • Is there another way except set_time_limit ? – ttrasn Apr 14 '15 at 09:28
  • 1
    you could use `time()` to get the timestamp at the beginning of the request. Then during your loop, check the current `time()` and if the difference is, say, `>10s` then you could issue a redirect to cause the page to reload (something like: `header('Location: script.php?last=10');`) Then use $_GET['last'] to figure out where you got to in your array (maybe use array splice?). If you make the timeout small enough you can log to the screen too using some kind of progress bar? – Nick Apr 14 '15 at 15:43
0
Step 1.htacces

RewriteEngine on
RewriteRule .* - [E=noabort:1]
RewriteRule .* - [E=noconntimeout:1]
SetEnv noconntimeout 1

Step 2. Litespeed server
/usr/local/lsws/conf/httpd_config.conf
find and replace
gracefulRestartTimeout           600 //or long time you want

Step 3. setting time out in php.ini
memory_limit = 1500M
post_max_size = 1500M
max_execution_time = 600
Vy Le Tien
  • 11
  • 2