Note that there are some explanatory texts on larger screens.

plurals
  1. POCall another php file
    primarykey
    data
    text
    <p>I'm building an iPhone push server, and trying to get the push to work. I have a message.php file which put new message in the database, and then add the message to a push_queue table in the database. </p> <p>To send the push, I manually have to go to the browser and call the push file (../push/push.php) which will send out the push. </p> <p>Is there any way I can call the push.php file from the message.php file automatically?</p> <p>I tried <code>require_one</code>, <code>include</code>, <code>exec</code> and <code>file_get_contents</code> without any luck.</p> <p>It works if I use:</p> <pre><code>header('Location: ../push/push.php'); </code></pre> <p>However, the push.php file takes a couple of seconds to execute and finish, so there's a delay for the user when trying to send a message. </p> <p>I guess I could use a cron job to call the push.php file, but I'd rather not.</p> <p>Here is the core function in push.php (based on <a href="http://www.raywenderlich.com/3525/apple-push-notification-services-tutorial-part-2" rel="nofollow">http://www.raywenderlich.com/3525/apple-push-notification-services-tutorial-part-2</a>):</p> <pre><code>function start() { //writeToLog('Connecting to ' . $this-&gt;server); if (!$this-&gt;connectToAPNS()) exit; while (true) { // Do at most 20 messages at a time. Note: we send each message in // a separate packet to APNS. It would be more efficient if we // combined several messages into one packet, but this script isn't // smart enough to do that. ;-) $stmt = $this-&gt;pdo-&gt;prepare('SELECT * FROM push_queue WHERE time_sent IS NULL LIMIT 20'); $stmt-&gt;execute(); $messages = $stmt-&gt;fetchAll(PDO::FETCH_OBJ); $deletedIds = array(); foreach ($messages as $message) { if ($this-&gt;sendNotification($message-&gt;message_id, $message-&gt;device_token, $message-&gt;payload)) { //$stmt = $this-&gt;pdo-&gt;prepare('UPDATE push_queue SET time_sent = NOW() WHERE message_id = ?'); //$stmt-&gt;execute(array($message-&gt;message_id)); $deletedIds[] = $message-&gt;message_id; //$stmt = $this-&gt;pdo-&gt;prepare('DELETE FROM push_queue WHERE message_id = ?'); //$stmt-&gt;execute(array($message-&gt;message_id)); } else // failed to deliver { $this-&gt;reconnectToAPNS(); } } //Delete the chunk of messages. $this-&gt;pdo-&gt;query('DELETE FROM push_queue WHERE message_id IN ('.implode(',', $deletedIds).')'); unset($messages); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload