-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Description
Description
The following code:
<?php
$url = 'https://example.com/';
$context = stream_context_create([
'http' => [
'timeout' => 60 * 60,
],
]);
file_get_contents($url, false, $context);
Resulted in this output:
file_get_contents(https://example.com/): Failed to open stream: timeout must be lower than 2147
But I expected this output instead:
No warning/error
Relavant code for the max value from the output ( floor((2^31 -1) / 1000000 ) = 2147 ):
php-src/ext/standard/http_fopen_wrapper.c
Lines 245 to 251 in cdaa69e
if (context && (tmpzval = php_stream_context_get_option(context, wrapper->wops->label, "timeout")) != NULL) { | |
double d = zval_get_double(tmpzval); | |
#ifndef PHP_WIN32 | |
const double timeoutmax = (double) PHP_TIMEOUT_ULL_MAX / 1000000.0; | |
#else | |
const double timeoutmax = (double) LONG_MAX / 1000000.0; | |
#endif |
Dividing by 100000.0 doesn't seem right.
The timeout struct accepts two long integers, one for seconds and one for micro seconds so the maximum value should be 2147483647.999999 seconds.
php-src/ext/standard/http_fopen_wrapper.c
Lines 259 to 265 in cdaa69e
#ifndef PHP_WIN32 | |
timeout.tv_sec = (time_t) d; | |
timeout.tv_usec = (size_t) ((d - timeout.tv_sec) * 1000000); | |
#else | |
timeout.tv_sec = (long) d; | |
timeout.tv_usec = (long) ((d - timeout.tv_sec) * 1000000); | |
#endif |
My php binary is from https://windows.php.net/downloads/releases/php-8.4.3-Win32-vs17-x64.zip
PHP Version
PHP 8.4.3 x64
Operating System
Windows 10
cmb69