| Issue 1: | Explain how to use |
1 of 2
Next ›
|
| 4 people starred this issue and may be notified of changes. | Back to list |
In the readme it says "To send messages, just add them to the queue!" What does this mean??? What php do we include and a code snippet would be handy. I can't see any function like add to queue in any of the code :-(
Jun 24, 2009
That isn't a very good example. The memcachd port is wrong and it doesn't explaint
the packet format. This is what I currently have:
<?php
$device_token = '00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000';
$text = 'no way this works';
$aps_message = '{"aps":{"alert":'.json_encode($text).', "sound":"default"}}';
$queue = new Memcache;
$queue->pconnect('localhost', 11211);
$queue->set('PushQueue', serialize(array($device_token, $aps_message)), 0, 0);
?>
The PushMonitor is not detecting the new item in the queue but I'll make a new issue
for that.
Jun 24, 2009
It's the right port for my memcached ! The APNS packet format is well documented, I figured most users would probably only be curious as to how the message is formatted in the queue (e.g. using serialize as this isnt mentioned in the documentation) Also, I would suggest that json_encode() is used to generate the $apnsMessage (or $aps_message in your example above) rather than just a string
Aug 24, 2009
I've tried to use your code but I've run into some problems when I add a message to the queue. Once the
PushMonitor script realises there is a message to send it creates an infinite loop where on each iteration I get
eg.
"a:2:{i:0;s:64:"DEVICETOKEN";i:1;s:17:"no way this works";}"
Sending message
Message sent
until eventually I run out of memory
Now it seems then that the message is not been removed from the queue and I don't know why. Is there any
obvious explanation for what is going on here or have I just missed something really obvious?
Aug 24, 2009
In response to comment 5 - I had the same issue and it was because i was using classic memcached instead of memcacheq - memcacheq removes items from the db as they are pulled (hence the queue). If you did manage to install memcacheq then use the command at the bottom of this page http://memcachedb.org/memcacheq/INSTALL.html to start that up instead of memcacheq
Aug 25, 2009
That is incredibly useful information. You have saved me a lot of time spent trying to figure this out. Thank you!
Aug 25, 2009
Hi, Is it possible to check if the service is running in PHP? Also, is it possible to start and stop the service via another PHP script? Thanks
Aug 25, 2009
I managed to solve the checking if the service is running problem, I added a pid file class in PushMonitor.php, it creates a pid file on startup and checks to see if one exists already. Let me know if you want me to share it.
Aug 26, 2009
@mikeytrw, that would be great to see that pid code. Thanks!
Aug 27, 2009
Right, I figure out that the memcacheq process was not running so I've installed that and started it up. In the logfile I can see the following lines which I assume mean that the process is running ok [memcacheq] [Thu Aug 27 09:33:52 2009] "memp_trickle thread: writing 0 dirty pages" [memcacheq] [Thu Aug 27 09:33:52 2009] "checkpoint thread: a txn_checkpoint is done" [memcacheq] [Thu Aug 27 09:34:22 2009] "memp_trickle thread: writing 0 dirty pages" But the problem I was having before where I was getting an infinite loop due to the push notification never being removed from the cache still remains. I'm scratching my head here wondering what is going on but I seem to be going round in circles. Does anyone have any ideas that might help me? Thank you!
Aug 27, 2009
Don't worry, I was using the wrong port all along.
Aug 28, 2009
"Don't worry, I was using the wrong port all along."
Common mistake, took me a wee while to figure out that memcached and memcacheq ran
together, independantly of each other - and you can connect to either using different
ports.
@coder.cotton
I ended up using different code to check the service is running :
/**
* @function serviceIsRunning
* @access public
* returns bool if the APNS Q processing service is running
*
*/
function serviceIsRunning(){
$running = false;
exec("ps -aux", $pslist);
foreach($pslist as $list){
if(strpos($list,'php -f /usr/local/PHP-APNS/PushMonitor.php'))
$running = true;
}
return $running;
}
Aug 28, 2009
I am getting a server hang when the PushMonitor tries to close the apple connection
after x seconds of inactivity, I narrowed it down to the code:
$pids = preg_split('/\s+/', `ps -o pid --no-heading --ppid $ppid`);
this is outputting:
Array
(
[0] =>
)
so obviously in the "foreach($pids as $pid)" loop the $pid is non_numeric.
Why do we need this, cant we just posix_kill the pid returned from proc_get_status???
Aug 28, 2009
Shouldnt :
elseif($debug)
{
echo "Attempt ",$i+1," failed\n";
if($process)
{
$process->kill();
$process = false;
}
}
be :
elseif($debug)
{
echo "Attempt ",$i+1," failed\n";
}
if($process)
{
$process->kill();
$process = false;
}
On line 135 in PushMonitor.php
Aug 31, 2009
Thank you #15 for your report. I've fixed that bug.
Status:
Fixed
|
An example; $strQueueMsg = serialize(Array($apnsToken,$apnsMessage)); $memcache_obj = memcache_connect('127.0.0.1', 22201); memcache_set($memcache_obj, 'queuename', $strQueueMsg, 0, 0); memcache_close($memcache_obj);