Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Build a PHP Queue System
    primarykey
    data
    text
    <p>I had to build a PHP Queue System, and found this brilliant article <a href="http://squirrelshaterobots.com/programming/php/building-a-queue-server-in-php-part-1-understanding-the-project/" rel="noreferrer">http://squirrelshaterobots.com/programming/php/building-a-queue-server-in-php-part-1-understanding-the-project/</a> and I used it to create a PHP queue system, its very easy to set-up and use.</p> <p>Below is the code for queue.php, run from shell (puTTy or somesuch).</p> <pre><code>&lt;?PHP //. set this constant to false if we ever need to debug //. the application in a terminal. define('QUEUESERVER_FORK', true); //////// fork into a background process //////// if(QUEUESERVER_FORK){ $pid = pcntl_fork(); if($pid === -1) die('error: unable to fork.'); else if($pid) exit(0); posix_setsid(); sleep(1); ob_start(); } $queue = array(); //////// setup our named pipe //////// $pipefile = '/tmp/queueserver-input'; if(file_exists($pipefile)) if(!unlink($pipefile)) die('unable to remove stale file'); umask(0); if(!posix_mkfifo($pipefile, 0666)) die('unable to create named pipe'); $pipe = fopen($pipefile,'r+'); if(!$pipe) die('unable to open the named pipe'); stream_set_blocking($pipe, false); //////// process the queue //////// while(1){ while($input = trim(fgets($pipe))){ stream_set_blocking($pipe, false); $queue[] = $input; } $job = current($queue); $jobkey = key($queue); if($job){ echo 'processing job ', $job, PHP_EOL; process($job); next($queue); unset($job, $queue[$jobkey]); }else{ echo 'no jobs to do - waiting...', PHP_EOL; stream_set_blocking($pipe, true); } if(QUEUESERVER_FORK) ob_clean(); } ?&gt; </code></pre> <p>The hardest part was getting the pcntl functions to work on my server. </p> <p>My question is "How do i get the job to start automatically when/if the server has to restart?"</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.
 

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