-1

I want to perform multiple for loops at once. For loop consists of socket operations. I want to send request and get response using socket. Current problem is that first of all First for loop executes and then second one. How do I perform simultaneously ? Please explain with example. This is the code :

<?php

for($i=0;$i<1000000;$i++)
{
  //Soecket operations
}  

for($i=0;$i<1000000;$i++)
{
  //Soecket operations
}  

for($i=0;$i<1000000;$i++)
{
  //Soecket operations
}  

for($i=0;$i<1000000;$i++)
{
  //Soecket operations
}  
for($i=0;$i<1000000;$i++)
{
  //Soecket operations
}  
for($i=0;$i<1000000;$i++)
{
  //Soecket operations
}  
for($i=0;$i<1000000;$i++)
{
  //Soecket operations
}  
for($i=0;$i<1000000;$i++)
{
  //Soecket operations
}  
for($i=0;$i<1000000;$i++)
{
  //Soecket operations
}  

?>

How can I perform all of them at once ?

Thank you!

Mark
  • 1

1 Answers1

1

Сreate bash script with calls to php scrips inside.

bash-start.sh

#!/usr/bin/env bash

    /bin/ps -auwx | /usr/bin/grep  custon-name-php-file.php | /usr/bin/awk  '{print $2}' | /usr/bin/xargs kill -9

    for i in `seq 1 15`;  # 15 - count threads
    do
       echo $i
        /usr/sbin/daemon custon-name-php-file.php $i
    done

custon-name-php-file.php

#!/usr/local/bin/php
<?php

$thread = $_SERVER['argv'][1];

for($i=0;$i<1000000;$i++)
{
  //Soecket operations
  echo $thread."). ".$i.PHP_EOL;
}  
Yevhen L.
  • 71
  • 7