Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change default_socket_timeout from my php code?

Tags:

php

timeout

In my php script I restore db2 database backups. They are getting bigger and bigger. So now I was getting 500 Server Error after +-30min after executing the script. There was this line in (mod_fastcgi.c.3352) response not received, request sent: 634 on socket: tcp:127.0.0.1:9090 for /wrational/restoredb.php?mode=restore&database=RATIONAL, closing connection in php-errors.log file.

I thought that setting `set_time_limit(6000);1 would solve the issue but it hasn't.

Increasing default_socket_timeout in php.ini file did the trick.

Is there any way to change default_socket_timeout from php code?

like image 872
Radek Avatar asked Jul 27 '12 05:07

Radek


People also ask

What is PHP Default_socket_timeout?

default_socket_timeout int. Default timeout (in seconds) for socket based streams. Specifying a negative value means an infinite timeout.

How to set timeout for HTTP request PHP?

The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php. ini . When called, set_time_limit() restarts the timeout counter from zero.


2 Answers

With this PHP command:

ini_set("default_socket_timeout", 6000);

Or add/update the .htaccess file with this line:

php_value default_socket_timeout 6000

Check the current value with phpinfo()

like image 152
huysentruitw Avatar answered Sep 19 '22 02:09

huysentruitw


beware of the fact, that php has a bug with default_socket_timeout and SSL. It will wait endless in case you use HTTPS/SSL.

https://bugs.php.net/bug.php?id=41631

like image 21
staabm Avatar answered Sep 20 '22 02:09

staabm