Re: FIFO files on PHP?
| From: | Al | Date: | Wed, 02 Jul 2008 00:55:03 +0000 |
| Subject: | Re: FIFO files on PHP? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-276205@lists.php.net to get a copy of this message | ||
Why not simply maintain an array as a file.
$fifoArray= unserialize(file_get_contents($fifoFile));
$oldValue= array_pop($fifoArray);//To pop off old value
array_unshift($fifoArray, $newValue);//To push in new value
$fifoStr= serialize($fifoArray);
file_put_contents($fifoArray, $fifoStr, LOCK_EX);
You can do the same thing by just using:
$fifoArray= file($fifoFile);
..same array_pop() and array_unshift() stuff
file_put_contents($fifoFile, $fifoArray, LOCK_EX);
You'll need to check for an empty array, etc.
Waynn Lue wrote:
I'm trying to build a queue out using FIFO files (someone on the MySQL list suggested checking them out instead of using the database), but I'm running into a problem because of the synchronous fwrite call. Here's the code: $fifoFile = '/tmp/fifo'; if (!file_exists($fifoFile)) {posix_mkfifo($fifoFile, 0600);} $fp = fopen($fifoFile, "w"); fwrite($fp, "content"); fclose($fp); But this will block until something actually reads the pipe. Is there any way to write to the pipe, then go away as opposed to waiting until something consumes it? Otherwise, I may just go back to a database table. Thanks, Waynn