0

I want to run multiple instances of the following script parallel:

for($i = 0; $i < 1000; ) {
   echo "It works! Woohoo.<br/>";
   sleep(1);

   flush();
   ob_flush();
 }

I have included the httpd-mpm.conf in Apache's httd.conf, but it still doesn't work. I'am using WAMP with Windows7. Is there a way to get this working?

Thanks!

6
  • 1
    call the script multiple times, i would suggest exec() Commented May 17, 2012 at 19:47
  • 1
    PHP is desperately single-threaded, there are so many things that would break if you brought in multithreading. You can use exec to spawn more processes, which will run asynchronously to your program, but that's about it AFAIK. Commented May 17, 2012 at 19:49
  • 1
    @Rocket Yes, it´s but everyone of us knows that that we can get multiple threads. Commented May 17, 2012 at 19:49
  • 1
    @zneak You could manually fork processes with the Pcntl extension (yuck), or you could call a script multiple times in parallel with curl_multi_exec() (example here). No option is really clean or desirable. :-) Commented May 17, 2012 at 19:53
  • 1
    @Wiseguy, I actually meant that spawning more processes was the only way to have parallelism, not that exec was the only way to do it. But yeah. I guess we agree. Commented May 17, 2012 at 19:54

2 Answers 2

3

PHP is single threaded, but there are some tricks to get multiple threads in order to offload heavy tasks to the background. One is to use Gearman, another is to use the new events introduced in PHP 5.4.

Sign up to request clarification or add additional context in comments.

Comments

0

Don't use PHP use CGI or Java Servlets.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.