php / php/php-src

Socket maximum timeout of 2147 seconds?

Open
#17,717 2 comments 1 reaction 1 assignee View on GitHub

@cmb69 is already working on this.

Since Feb 6, 2025.

Bug Extension: standard OS: Windows Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

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 ):
https://github.com/php/php-src/blob/cdaa69e1224bac08be5cdca58191e096613c5766/ext/standard/http_fopen_wrapper.c#L245-L251
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.

https://github.com/php/php-src/blob/cdaa69e1224bac08be5cdca58191e096613c5766/ext/standard/http_fopen_wrapper.c#L259-L265

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.