Voting

: min(seven, nine)?
(Example: nine)

The Note You're Voting On

TorokAlpar at Gmail dot com
17 years ago
Here is a possible solution to what - tech at kwur dot com- mentioned:

I faced the problem where i had a process (a server) that needed to take care of socket connection, and in the meanwhile get some data from the database. I didn't wanted to make the clients wait for the query execution time, so i decided to make a separate process that executes the query on the DB, and the two would communicate over a pipe. Of course i didn't wanted the server blocking if no data was available. So what i come up with is to use stream_select() , and to overcome the mentioned problem, i would fork the process, open up the pipe for writing in the child, this way the parent won't block when it opens the pipe.

here is some code

<code>

<?php

if (pcntl_fork() == 0)
{
// kid
$file = fopen("JobsQueue","w");
sleep(1);
exit(
0);
}
else
{
usleep(15); // make sure that the child executes first
$file = fopen("JobsQueue","r");
}

echo
"opened the queue \n";

while (
true)
{
$reders = array($file);
if (
stream_select($reders,$writers=null,$except=null,0,15) < 1)
{
continue;
}
else
{
// read data from the fifo
$data = fread($file,1024);
echo
$data;
}
sleep(1);
}

?>

</code>

<< Back to user notes page

To Top