I want to write an Ajax web application, a game to be specific. Two web clients have to communicate with each other via the PHP server. My approach to solve this is to use A
Just a short statement, that I actually found a nice solution using named pipes:
public function createPipe_test(){
posix_mkfifo("testpipe", 0777);
}
public function writePipe_test($value){
$pipeA = fopen("testpipe",'w');
$valueString = number_format($value);
$valueLen = number_format(strlen($valueString));
fwrite($pipeA, $valueLen);
fwrite($pipeA, $valueString);
}
public function readPipe_test(){
$pipeB = fopen("testpipe",'r');
$valueLen = fread($pipeB, 1);
return fread($pipeB, $valueLen);
}
I have two processes.
If process 1 calls writePipe_test(), then it waits until process 2 calls readPipe_test() to read the data out of the pipe.
If process 1 calls readPipe_test(), then it waits until process 2 calls writePipe_test() to write something into the pipe.
The trick is 'w' and 'r' instead of 'r+'.