1
    $users = $db->query('SELECT * FROM users ORDER BY RAND() LIMIT '.$limit)->fetchAll();
    foreach($users as $user){
        $cookie = $_SERVER['DOCUMENT_ROOT'].'/data/'.md5($user['id']);
        echo StartFun($id, $type, $cookie);
    }

I want to run StartFun function multiple times in parallel with different values of $cookie, how can i do this?
Please help me for this, i googles to solved this but didn't got any good results.

  • 3
    Possible duplicate of [How can one use multi threading in PHP applications](http://stackoverflow.com/questions/70855/how-can-one-use-multi-threading-in-php-applications) – Havenard Nov 29 '16 at 19:35
  • @Havenard no this isn't a duplicate question. I want different values of `$cookie` and want to run same function multiple times. – Drake Singh Nov 29 '16 at 19:37
  • 1
    You can start threads with different parameters. – Havenard Nov 29 '16 at 19:39
  • What doesn't work with your current code??? – AbraCadaver Nov 29 '16 at 19:39
  • @Havenard can you please give me a sample code for that? – Drake Singh Nov 29 '16 at 19:40
  • @AbraCadaver i want to make it more faster, like 100 executions per second. – Drake Singh Nov 29 '16 at 19:41
  • Sorry I don't have an example of how do to do that, all I know is that it is possible. Also, if you expect it to be 100 times faster I doubt you will get that, unless you have a 100 real cores CPU. Maybe you should better identify what is your bottleneck and try a different approach there. PHP is nice, but it is not fast. – Havenard Nov 29 '16 at 19:46
  • @Havenard i do have good hardware, you don't need to worry about that. – Drake Singh Nov 29 '16 at 19:47
  • @DrakeSingh The power of the output buffer and the fastness of PHP will be limited. However pthreads is the answer as Havenard suggested I guess if you want parallel execution. – Blackbam Nov 29 '16 at 19:48
  • Here is an example of how I improved the performance of a PHP code to run several hundreds of times faster. I hope it gives you some ideas http://codereview.stackexchange.com/questions/62233/improving-performance-of-a-search-in-php – Havenard Nov 29 '16 at 19:48

0 Answers0