我正在向iPhone设备发送推送消息通过steam_socket使用php.It工作正常,但我想发送1000条记录,在这种情况下,我只得到50条消息,然后我得到Warning: stream_set_timeout():
我怎么能增加流套接字时间有没有办法处理这种类型的问题可以任何人请指导我。
这是我的代码
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);
}
感谢您提前。
答案 0 :(得分:0)
摘自PHP手册中的用户帖子:
<?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));
?>