Giter Site home page Giter Site logo

Explain how to use about php-apns HOT 16 CLOSED

codexprojects avatar codexprojects commented on July 20, 2024
Explain how to use

from php-apns.

Comments (16)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 20, 2024
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);

Original comment by [email protected] on 24 Jun 2009 at 9:16

from php-apns.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 20, 2024
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.

Original comment by [email protected] on 24 Jun 2009 at 9:28

from php-apns.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 20, 2024
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

Original comment by [email protected] on 24 Jun 2009 at 10:11

from php-apns.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 20, 2024
[deleted comment]

from php-apns.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 20, 2024
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?

Original comment by [email protected] on 24 Aug 2009 at 1:11

from php-apns.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 20, 2024
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

Original comment by [email protected] on 24 Aug 2009 at 6:10

from php-apns.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 20, 2024
That is incredibly useful information. You have saved me a lot of time spent 
trying to figure this out. Thank you!

Original comment by [email protected] on 25 Aug 2009 at 7:47

from php-apns.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 20, 2024
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

Original comment by [email protected] on 25 Aug 2009 at 10:18

from php-apns.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 20, 2024
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.

Original comment by [email protected] on 25 Aug 2009 at 10:40

from php-apns.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 20, 2024
@mikeytrw, that would be great to see that pid code.  Thanks!

Original comment by coder.cotton on 27 Aug 2009 at 2:33

from php-apns.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 20, 2024
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!

Original comment by [email protected] on 27 Aug 2009 at 8:41

from php-apns.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 20, 2024
Don't worry, I was using the wrong port all along.

Original comment by [email protected] on 28 Aug 2009 at 6:47

from php-apns.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 20, 2024
"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;        
    }


Original comment by [email protected] on 28 Aug 2009 at 10:14

from php-apns.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 20, 2024
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???

Original comment by [email protected] on 28 Aug 2009 at 11:10

from php-apns.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 20, 2024
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

Original comment by [email protected] on 28 Aug 2009 at 3:58

from php-apns.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 20, 2024
Thank you #15 for your report.
I've fixed that bug.

Original comment by [email protected] on 31 Aug 2009 at 9:02

  • Changed state: Fixed

from php-apns.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.