php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47629 mysqli connect timeout causes fatal error
Submitted: 2009-03-12 04:41 UTC Modified: 2009-10-19 15:19 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: danielc at analysisandsolutions dot com Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.3CVS-2009-03-12 (snap) OS: Windows XP SP3
Private report: No CVE-ID: None
 [2009-03-12 04:41 UTC] danielc at analysisandsolutions dot com
Description:
------------
A fatal error is generated if a MySQLi connection attempt times out AND the default_socket_timeout ini setting is greater that the max_execution_time ini setting.  This is happening in PHP 5.3, Mar 11 2009 17:04:24, VC6 thread safe snapshot build.

This does not happen on timeouts when using socket_bind().

This does not happen in PHP 5.2.9-1.

Reproduce code:
---------------
// BOGUS MYSQL PORT NUMBER IS INTENTIONAL.

echo 'PHP ' . phpversion() . "\n\n";

echo "ONE ---------------\n";

ini_set('max_execution_time', 6);
ini_set('default_socket_timeout', 2);

echo 'max_execution_time: ' . ini_get('max_execution_time') . "\n";
echo 'default_socket_timeout: ' . ini_get('default_socket_timeout') . "\n";

$mysqli = new mysqli('localhost', 'does', 'not', 'matter', 1);
if ($mysqli->connect_error) {
    echo "GOOD CATCH\n\n";
}


echo "TWO ---------------\n";

ini_set('max_execution_time', 2);
ini_set('default_socket_timeout', 6);

echo 'max_execution_time: ' . ini_get('max_execution_time') . "\n";
echo 'default_socket_timeout: ' . ini_get('default_socket_timeout') . "\n";

$mysqli = new mysqli('localhost', 'does', 'not', 'matter', 1);
if ($mysqli->connect_error) {
    echo "GOOD CATCH\n\n";
}


Expected result:
----------------
PHP 5.3.0beta2-dev

ONE ---------------
max_execution_time: 6
default_socket_timeout: 2

Warning:  mysqli::mysqli() [mysqli.mysqli]: [2002] A connection attempt failed because the connected party did not  (trying to connect via tcp://localhost:1) in ...

Warning:  mysqli::mysqli() [mysqli.mysqli]: (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in ...

GOOD CATCH

TWO ---------------
max_execution_time: 2
default_socket_timeout: 6

Warning:  mysqli::mysqli() [mysqli.mysqli]: [2002] A connection attempt failed because the connected party did not  (trying to connect via tcp://localhost:1) in ...

Warning:  mysqli::mysqli() [mysqli.mysqli]: (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in ...

GOOD CATCH


Actual result:
--------------
PHP 5.3.0beta2-dev

ONE ---------------
max_execution_time: 6
default_socket_timeout: 2

Warning:  mysqli::mysqli() [mysqli.mysqli]: [2002] A connection attempt failed because the connected party did not  (trying to connect via tcp://localhost:1) in ...

Warning:  mysqli::mysqli() [mysqli.mysqli]: (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in ...

GOOD CATCH

TWO ---------------
max_execution_time: 2
default_socket_timeout: 6

Warning:  mysqli::mysqli() [mysqli.mysqli]: [2002] A connection attempt failed because the connected party did not  (trying to connect via tcp://localhost:1) in ...

Warning:  mysqli::mysqli() [mysqli.mysqli]: (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in ...

Fatal error:  Maximum execution time of 2 seconds exceeded in ...


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-20 13:19 UTC] pajoye@php.net
With:

max_execution_time: 2
default_socket_timeout: 6


It is the expected behavior to have a fatal error about the maximum execution time being exceeded. max_execution_time has the highest importance.
 [2009-06-20 17:34 UTC] danielc@php.net
Yes, the execution timeout makes sense some ways.  The problem is the behavior is inconsistent between 5.2 and 5.3 and between other connection functions.
 [2009-06-20 20:12 UTC] pajoye@php.net
but there is no bug here. Why do you want to let the socket timeout override the main timeout?
 [2009-06-21 00:48 UTC] danielc at analysisandsolutions dot com
Because:
1) That's how PHP 5.2 does it.
2) That's how the other socket functions do it in 5.2 and 5.3.
3) The timeout is from communication with another entity, not from the script itself.
 [2009-06-21 09:04 UTC] pajoye@php.net
"1) That's how PHP 5.2 does it."

Not really relevant in this case.

"2) That's how the other socket functions do it in 5.2 and 5.3."

Then there is a bug here.

"3) The timeout is from communication with another entity, not from the
script itself."

The max_execution_time has the highest priority and should always has it. If it is not the case in one function or another then there is a bug in this function.
 [2009-06-22 15:58 UTC] danielc at analysisandsolutions dot com
I'll put together tests of the various functions and report back.
 [2009-09-17 11:40 UTC] uw@php.net
I don't see a bug here either.

The windows binaries from php.net default to mysqlnd as of PHP 5.3. The PHP 5.2 ones should use the MySQL Client Library. The MySQL Client Library uses its own network layer abstraction whereas mysqlnd uses PHP streams. 

The default CONNECT_TIMEOUT of mysqlnd is 0, unless overruled by API settings (mysql.connect_timeout,  MYSQLI_OPT_CONNECT_TIMEOUT, <whatever_may_set_php_streams_default>, ...). The MySQL Client Library uses the same default. Both PHP streams and the MySQL Client Library pass the value down to the network functions. 

Regarding READ_TIMEOUT please see http://bugs.php.net/bug.php?id=49511 . 

Seems that your main point is about the Fatal error. In my eyes this is what shall happen - no bug:

"Note: The set_time_limit() function and the configuration directive max_execution_time  only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real.", http://de3.php.net/set_time_limit

According to the documentation the time limit on Windows is real time. That is wall clock. The script should stop after max_execution_time - default_socket_timeout > max_execution_time does not matter.

The question is if/why the timeout does not happen (on PHP 5.2, 5.3?) when using the MySQL Client Library on Windows. The way I read the manual time spend on database operations should be taken into account on Windows. 

And that is a matter of the PHP time limit functionality (-> Category: General/similar not MySQLi related)
 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Feb 09 07:05:47 2023 UTC