0

I'm using curl to get a live content from a server. Each time this server gives me a specific answer, I would like to send another curl request (not a stream one).

I have tried to use curl_multi_init but it doesn't seem to be the correct usage. curl_multi_init allows me to send several requests at the same moment, but I don't know if I can send a request while keeping the "stream request".

What I want to do, is :

AAAAAAAAAAAAAAAAAAAAAA
B        C           D

Where A is the stream request which should never stop, and B, C, D several requests sent thanks to A.

Is it possible to do this thanks to PHP? Thanks a lot.

Vico
  • 1,696
  • 1
  • 24
  • 57
  • This may be possible with pthreads - see http://stackoverflow.com/q/70855/3794472 - but you'd probably have better results doing this in a language with native async processing. – Jeremiah Winsley Nov 26 '14 at 19:34
  • 1
    PHP ain't good in multithreading, so, in a single thread, you'd `fopen()` an url, you'd nibble at it with small `fread()`'s at a time in a loop (possibly use `stream_set_blocking` if you need non-blocking reading), and when an event is 'triggered', fire of that request & do that first. Note: this means you can only do this with 1 continuous stream at a time, if there's an option that 1 will become several, I'd go for a language with multithreading. – Wrikken Nov 26 '14 at 19:34
  • Thanks for your comments guys. Do you have a few languages to recommend to orientate my researches? – Vico Nov 26 '14 at 19:37
  • I've used Go (https://golang.org/) for something similar. It makes multithreading pretty easy. But it looks like you've worked with Javascript, so maybe Node.js (nodejs.org) would be easier for you to pick up. – Jeremiah Winsley Nov 26 '14 at 21:21

0 Answers0