Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You really need to run a PHP daemon in order to do this effectively (and it NEEDS to be PHP 5.3). I wrote a fairly completely overview of using <a href="https://stackoverflow.com/questions/4169412/how-to-design-a-daemon-with-a-mysql-db-connection/4169523#4169523">PHP for daemon processes</a>. Whatever you chose, I would suggest you use an event based, run loop system.</p> <p>I've designed a basic RunLoop library called <a href="https://github.com/Wordi/LooPHP" rel="nofollow noreferrer">LooPHP</a> which could probably be helpful, especially if your going to be dealing with <code>*_select</code>. I'd be more than happy to answer any question you have about that.</p> <p>EDIT:</p> <p>In an event based system you don't simply <code>while</code> a list of commands, you react to a listener. For example...</p> <p>Instead of doing:</p> <pre><code>while( 1 ) { ... /* listen, react */ } /* repeat */ </code></pre> <p>Run loops work by registering listener (sockets, and other async event generators)</p> <pre><code>class ReactClass { ... } $loop = new LooPHP_EventLoop( new ReactClass ); //add one time event $loop-&gt;addEvent( function() { print "This event was called 0.5 second after being added\n"; }, 0.5 /* in seconds */ ); //this creates a repeating event, this is called right away and repeats $add_event = function() use ( $loop, &amp;$add_event ) { print "This event is REPEATEDLY called 0.1 every second\n"; $loop-&gt;addEvent( $add_event, 0.1 ); }; $add_event(); //start the loop processing, no events are processed until this is done $loop-&gt;run(); //php doesn't leave this call until the daemon is done exit(0); //cleanly exit </code></pre> <p>The above case is a very simple 1 source EventLoop and a manually add timed functions ( these can be added even from within a call to <code>ReactClass</code>).</p> <p>In the application I'm working I needed to have both asynchronous event feed into the backend (via a socket) and then needed to have the ability to call functions arbitrary offset from the original event (for timed-out clients, etc).</p> <p>If you'd like more examples, you can find them over at <a href="https://github.com/Wordi/LooPHP/blob/master/examples/" rel="nofollow noreferrer">github</a>.</p> <p>I hope you find this useful.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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