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?

4
  • 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. Commented Apr 25, 2013 at 8: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. Commented Apr 25, 2013 at 8: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. Commented Apr 25, 2013 at 8:13
  • Half of it is single words Commented Apr 25, 2013 at 8:15

3 Answers 3

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.

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

Comments

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.

3 Comments

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.
That will not give you the multi-thread effect that he is looking for since the system command does not run asynchronously.
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.
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.