I am sending push message to iPhone devices Through steam_socket using php.It's working fine but i want to send a 1000 records at time in that case i get only 50 messages then i get Warning: stream_set_timeout():
how could i increase stream socket time is there any way to handle this type problem can any one please guide me.
here is my code
for($i=0;$i<100;$i++)
{
$gstr="3f3dad52b4fb50001cb223253a3d995542209d354eXXXXXXXXXXXXXXXX";
pushMessage($gstr,$_REQUEST['msg'].$i,"Thinkingofyou");
}
function pushMessage($deviceToken,$message,$app) {
echo "Sending iPhone Push Notifications to " . $deviceToken . "<br /><br />";
echo "Your Message: " . $message . "<br />";
$time = time();
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'aps-toyPush.pem';
$streamContext = stream_context_create();
stream_set_timeout($streamContext, 3600);
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
//stream_context_set_option($streamContext, 'ssl', 'passphrase', $passphrase);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
if($apns) {
$payload = array();
$payload['aps'] = array('alert' => $message, 'badge' => 1, 'sound' => 'default');
$payload = json_encode($payload);
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);
} else {
echo "Connection Failed - iPhone Push Notifications Server";
echo $errorString."<br />";
echo $error."<br />";
}
// socket_close($apns);
fclose($apns);
}
Thanks for advance.
Taken from a user's post in the PHP manual:
<?php
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec'=>$sec, 'usec'=>$usec));
socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec'=>$sec, 'usec'=>$usec));
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.