I have got same questions in stackoverflow and tried all answers but no help. I am not getting what is the error.
Here is my function that i am using:
I get this error many times.
To resolve it, just before fwrite()
I added a sleep(5);
.
Now, every queries are returned with success.
Thanks for replying I found similar solutions in google that you should write to socket again. In m case code was throwing exception so I am managing that. So Now I am doing it like this
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
try {
$result = fwrite($fp, $msg, strlen($msg));
}
catch (Exception $ex) {
// try once again for socket busy error (fwrite(): SSL operation failed with code 1.
// OpenSSL Error messages:\nerror:1409F07F:SSL routines:SSL3_WRITE_PENDING)
sleep(5); //sleep for 5 seconds
$result = fwrite($fp, $msg, strlen($msg));
if ($result)
{
return true;
}
else {
return false;
}
}
Now it is not throwing that error in most of the cases. What I found that it happens when socket is busy so I am trying to write again after 5 seconds now. So I guess this should not come again. It is not live yet but in our testing we did not found this issue again. Can you suggest that I am going in right direction? When this code will be live then there will be a huge number of push notifications then in that case will it work fine or is there any other solution in your mind? Thanks for help :)
When you are trying to write to the socket. If something goes wrong, fwrite will return false or 0 (depending on the php version) as the return value. When it happens, you must manage it.
For the above issue the reason is pretty simple: when SSL_Write returns with SSL_ERROR_WANT_WRITE or SSL_ERROR_WANT_READ, you have to repeat the call to SSL_write with the same parameters again, after the condition is satisfied (read/write available on the socket).
Calling it with different parameters, will yield the 1409F07F bad write retry error.