0
votes

I have an iOS app, I used apple push notification to send the notification when I write new post in my site, so there is php script has the ssl certificates , when I send the push notification it's usually deliver but in the error log I got this error:

[27-Mar-2013 15:30:44] PHP Fatal error: Maximum execution time of 30 seconds exceeded in /home3/basiphon/public_html/Push.php on line 56

The push notification (usually) deliver successfully but I got this error in the error log, and there are sometimes the push notifcation not deliver and I got also this error to another error like this :

[27-Mar-2013 05:45:04] PHP Warning: stream_socket_client() [function.stream-socket-client]: SSL: connection timeout in /home3/basiphon/public_html/Push.php on line 56 [27-Mar-2013 05:45:04] PHP Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /home3/basiphon/public_html/Push.php on line 56 [27-Mar-2013 05:45:04] PHP Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.push.apple.com:2195 (Unknown error) in /home3/basiphon/public_html/Push.php on line 56

Please see the code of my push.php script :

 `// Open a connection to the APNS server

    $fp = stream_socket_client(
        $url, $err,
        $errstr, 2, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
    if (!$fp)
        exit("Failed to connect: $err $errstr" . PHP_EOL);

    echo 'Connected to APNS' . PHP_EOL;
    // Build the binary notification
    $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

    // Send it to the server
    $result = fwrite($fp, $msg, strlen($msg));

    if (!$result)
        echo 'Message not delivered' . PHP_EOL;
    else
    {
        echo 'Message successfully delivered111' . PHP_EOL;
        $query_update="update wp_apns_messages set status='delivered',delivery=NOW() where pid='$pid'";
        $res_update=mysql_query($query_update) or die(mysql_error());
    }

    // Close the connection to the server
    fclose($fp);`
1
Please post the relevant PHP code here in text form, there's a whole bunch of reasons why a screenshot is a bad idea.Tom Walters
Ok thanks tom, here the full code of my push.php script , I will edit the post and put text of script codeHussain1982
I should've mentioned, you need to edit your question rather than post a comment, with the code.Tom Walters
I edited the question , I can't put the full code but I add the last part of the script .Hussain1982

1 Answers

0
votes

I've had the same error before when running the PHP script provided by a push notification tutorial on www.raywenderlich.com.

Make sure you aren't running any firewalls interfering with your connection to APNs.

If you are following the aforementioned site's tutorial, make sure you are receiving a response and not an error when running the following in terminal:

$ openssl s_client -connect gateway.sandbox.push.apple.com:2195 
-cert PushChatCert.pem -key PushChatKey.pem
Enter pass phrase for PushChatKey.pem: