9

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'));
2
  • 1
    please state clearly what you want to achieve and what is currently happening!? Commented Apr 14, 2015 at 9: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'. Commented Apr 14, 2015 at 9:07

5 Answers 5

23

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]
Sign up to request clarification or add additional context in comments.

1 Comment

My man, thank you! You saved my desk from my head. If anyone else stumbles across this, here is some more information on the noabort and noconntimeout settings in Litespeed.
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.

4 Comments

thanks , but set_time_limit dont work for me , what can i do ?
@user3415984 To what value you set it?
i set set_time_limit(0) or set_time_limit(20), but not working :(
@user3415984 If setting it to 0 not helps and you wait ~30s to get timeout, contact your server administrator
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

2 Comments

Is there another way except set_time_limit ?
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?
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

Comments

0

I had the same problem and SimonE's answer is working great but find out I could handle this from php side by increasing value of both max_input_time and max_execution_time in php.ini configuration file.

Tip: You can use /usr/local/bin/php --ini | grep 'Loaded Configuration File' shell command to find location of php.ini configuration file in your linux.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.