Mutltithreading in PHP
Mutltithreading in PHP
In PHP, the multithreading concept is implemented by using popen function, by using this we can open a script for execution. It creates a file pointer like fopen, by using this pointer we can read the scripts by using fread or fgets function.
The Sample Script for multithreading is shown below
$commands = array(”php test.php”,”php test1.php”);
// Open all commands in read mode
for ($p=0; $p <count($commands); $p++)
{
$fh[$p] = popen($commands[$p],”r”);
}
// Reading all scripts using fread, here we can also use fgets
for ($p=0; $p <count($commands); $p++)
{
$farr = explode(” “,$commands[$p]);
$fname = $farr[1];
$st = fread($fh[$p],filesize($fname));
}
