2

What's the best way to go about running jobs in a foreach in parallel in PHP? Is there a best practice for this? Thanks

user528451
  • 133
  • 2
  • 11
  • http://stackoverflow.com/questions/6107339/parallel-processing-in-php-how-do-you-do-it?rq=1 – hjpotter92 Apr 02 '13 at 16:15
  • foreach? what exactly you want to parallelize? – Your Common Sense Apr 02 '13 at 16:16
  • Each iteration makes a function call that is time consuming (can take several seconds). Was wanting to run the iterations in parallel. I've been able to do this using shell scripting languages but no idea how to do it in PHP (if it can be done). – user528451 Apr 02 '13 at 16:18
  • @hjpotter92 that thread recommends exec but I've heard people say not to use it – user528451 Apr 02 '13 at 16:21
  • @user528451 `exec` is fine if you either don't allow user input into the command, or handle it correctly. `exec` is an easy way to fire off a background process without waiting for the result. – datasage Apr 02 '13 at 16:49

2 Answers2

2

The answer is simple: Parallel processing as a language feature isn't supported by php

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
1

php doesn't support threading. The most it offers is forking.

CrayonViolent
  • 32,111
  • 5
  • 56
  • 79