The decimal part of timeout parameter of stream_context is ignored
- Dominant language
- C++
- Stars
- 18.7k
- Forks
- 3.1k
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 2
Description
### HHVM Version
3.12.0
### Standalone code, or other way to reproduce the problem
Firstly let's write a dummy slow http server in Python, sleep 5 seconds before respond:
```
#!/usr/bin/env python
"""
Very simple HTTP server in python.
Borrowed from https://gist.github.com/bradmontgomery/2219997
Usage::
./dummy-web-server.py []
"""
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import SocketServer
import time
class S(BaseHTTPRequestHandler):
def _set_headers(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
def do_GET(self):
time.sleep(5)
self._set_headers()
self.wfile.write("
hi!
")def run(server_class=HTTPServer, handler_class=S, port=80):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print 'Starting httpd...'
httpd.serve_forever()
if __name__ == "__main__":
from sys import argv
if len(argv) == 2:
run(port=int(argv[1]))
else:
run()
```
Then php code:
```
'GET', 'timeout' => $argv[1]);
$contextid = stream_context_create(array('http' => $options));
$handle = @fopen('http://localhost:8269', 'r', false, $contextid);
if ($handle === FALSE) {
echo "Fail!\n";
} else {
echo "Succ!\n";
}
```
Start the server: `python dummy-web-server.py 8269`
Then try to run the php code with timeout 1, 0.1, 1.5: `time hhvm test.php 1|1.5|0.1`
### Expected result
All of the three running will fail, and the time cost should be around 1, 0.1, 1.5 respectively.
### Actual result
```
liang@xxx:~$ time hhvm test.php 1
Fail!
real 0m1.197s
user 0m0.090s
sys 0m0.102s
liang@xxx:~$ time hhvm test.php 1.5
Fail!
real 0m1.187s
user 0m0.100s
sys 0m0.087s
liang@xxx:~$ time hhvm test.php 0.1
SlowTimer [5005ms] at curl: http://localhost:8269
Succ!
real 0m5.157s
user 0m0.120s
sys 0m0.032s
```
We can see the decimal part is ignored, so that 1 and 1.5 are same, and 0.1 will be considered as no timeout.
Contributor guide
Assessment
This issue has not been assessed yet.