Skip to content

Instantly share code, notes, and snippets.

@cvuorinen
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvuorinen/1640b1a8ff2a7a19dd8e to your computer and use it in GitHub Desktop.
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
<?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);
@rdlowrey
Copy link

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