-
-
Save cvuorinen/1640b1a8ff2a7a19dd8e to your computer and use it in GitHub Desktop.
Example code to reproduce SSL socket stream bug, which causes it to hang and use 100% CPU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('max_execution_time', 10); | |
$url = 'ssl://gateway.sandbox.push.apple.com:2195'; | |
$ssl = [ | |
'local_cert' => 'path/to/valid/apns_sandbox.pem', | |
]; | |
$sock = stream_socket_client( | |
$url, | |
$errno, | |
$errstr, | |
ini_get('default_socket_timeout'), | |
STREAM_CLIENT_CONNECT, | |
stream_context_create(array( | |
'ssl' => $ssl, | |
)) | |
); | |
// this setting makes it use 100% cpu until timeout | |
// without this it also hangs until timeout, but doesn't use 100% cpu | |
stream_set_blocking($sock, 0); | |
$data = null; | |
if (!feof($sock)) { | |
$data = fread($sock, 1024); | |
} | |
var_dump($data); |
I'm working on this today. Will update the actual bug report when fixed.
This should now be corrected upstream as noted in the original bug report
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected result:
Actual result:
So far, only been able to reproduce with PHP 5.6.7 on Ubuntu 14.04. Works fine on CentOS with PHP 5.4, 5.5 and 5.6.