Advertisement
d34n

PHP ssl timeout bug

Mar 7th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. <?php
  2. // Should time out at 5 seconds for each connection
  3.  
  4. test('php.net:80');
  5. test('ssl://php.net:443');
  6.  
  7.  
  8. function test($host){
  9.         $socket = stream_socket_client($host, $errno, $errstr, 15);
  10.         echo "connect to $host errno=$errno errstr=$errstr\n";
  11.         if($socket && $errno==0) echo "connected\n"; else echo "connection error\n";
  12.         stream_set_timeout($socket,5);
  13.         $connect_time=time();
  14.  
  15.         while($data=fgets($socket)){ }
  16.         $meta=stream_get_meta_data($socket);
  17.         if($meta['timed_out']){
  18.                 $timed=time()-$connect_time;
  19.                 echo "timed out after $timed seconds\n";
  20.         }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement