3

I have some code that does something like this pseudocode:

Use CURL to get site1 into a variable
Use CURL to get site2 into a variable
Use CURL to get site3 into a variable
Use CURL to get site4 into a variable

Do lots of processing on each

Produce output

echo output

Currently this takes a long time occasionally.

I'd like to get the CURL bit to run in parallel so I can get things to speed up.

How do I do that?

4
  • 1
    stackoverflow.com/questions/2253791/… Commented Nov 5, 2011 at 19:24
  • I'm not sure if this actually makes it faster, but you can try execute each curl in a separate thread. Commented Nov 5, 2011 at 19:24
  • You can try to open subprocesses using proc_open() in non-blocking mode. Sorry, but to lazy for a full answer Commented Nov 5, 2011 at 19:26
  • Maybe create 4 daemons to do the work: pear.php.net/package/System_Daemon Commented Nov 5, 2011 at 19:30

3 Answers 3

2

I think you are looking for this http://php.net/manual/en/function.curl-multi-init.php parallel cURL requests.

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

Comments

0

As far as I know php does not support asynchronous IO.

But I can recommend on Node.js,which does support it and that's it's advantage. An additional advantage of Node.js is that you can use your form validations on client and on server side.

1 Comment

There are other solutions that have multithreading and what is really the strength of Node.js is actually ability to execute the script in a way it would be executed in the browser. So, basically, if you know JavaScript well engough, Node.js will be much easier to learn than eg. Python's Twisted.
0

Just for future people, I'm actually planning to move some of the logic to the client, then use AJAX to request the PHP files with one CURL in each file. This way I can request all files at once, then use JS to parse and tidy up the results.

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.