0

My website has source pages that use ob_start() and $content = ob_get_clean(). Inside them I'm using a function multiple times that uses curl and bing to translate words/phrases into a specified language.

If the translation has been done before it looks it up in a database, otherwise it gets a reply from bing in series. I want it to do it in parallel so that it translates the page a lot faster. Any ideas?

Luke Wenke
  • 1,149
  • 2
  • 23
  • 43
  • 1
    I'm going to go with don't use automatic translations. The results will be incredibly bad. See if you can get volunteers or something to help your translate the pages. – Jon Apr 25 '13 at 08:07
  • My boss wants to use automatic translations... though I've made it so that people can edit the previous translations that have been stored in a database. – Luke Wenke Apr 25 '13 at 08:09
  • Ahh, well if you must do it, then you must I suppose. At least you built in a way for real translations in to it. Are you doing phrases or single words? Single works will be a lot worse as the context can change depending on how/when it is used in a phrase. – Jon Apr 25 '13 at 08:13
  • Half of it is single words – Luke Wenke Apr 25 '13 at 08:15

3 Answers3

1

PHP Doesn't natively support Parallel processing indeed. There are however, ways to simulate it as shown on this page: http://www.d-mueller.de/blog/parallel-processing-in-php/

The idea behind it, is that you make a process manager or something similar that manages the threads running on the background and checks their status. Because they are background processes, you can start multiple of them. You manager can than continue your script when they are all done.

Anyone
  • 2,814
  • 1
  • 22
  • 27
0

Unfortunately I think in PHP there is no parallel processing. The only way to simulate parallel processing as far as I know would be to use a clever cron job, and initiate multiple instance of it.

  • eesh. If your `cron` job is doing that, it's definitely not clever. You can, technically, use something like `system('/path/to/php /path/to/script.php &');` as the `&` will allow the return to the page without waiting for `script.php` to finish, but that _really_ shouldn't be used either. – Jon Apr 25 '13 at 08:09
  • That will not give you the multi-thread effect that he is looking for since the system command does not run asynchronously. – Hermann Stephane Ntsamo Apr 25 '13 at 08:15
  • But, amazingly, the `&` at the end of the command will drop you out of `system` and let your script continue - which would technically be a parallel process, though you won't get a return from it. – Jon Apr 25 '13 at 08:20
0

Several parallel php processes(not threads) can be done with gearman try http://gearman.org/ for gearman