1

I'm creating something that looks like an RSS reader. People set up subscriptions (from other websites), and I fetch content from them.

I'm working with symfony2 and am currently facing a problem: how do I dispatch, asynchronously, http requests to many urls using symfony2? I know it can be done using cURL, but I'd like to think there's already a bundle for that. I've checked krisswallsmith/buzz and sensio/buzz, but they are poorly documented, apparently outdated (sensio/buzz still uses the vendor script to be installed) and potentially don't allow me to dispatch requests asynchronously - I wouldn't know, as I said, they are poorly documented.

Is there a bundle? If so, which one? If not, what technique should I use to achieve my goal? Should I create a separate bundle just to handle the requests? Should I go inside my controller and write some ugly cURL stuff within my actions? Should I create a service to handle the dispatches?

cwallenpoole
  • 79,954
  • 26
  • 128
  • 166
Pedro Cordeiro
  • 2,085
  • 1
  • 20
  • 41
  • Just to be clear: You want to do a http request to a specific site and store/handle the response every now and then? – Sgoettschkes Apr 02 '13 at 13:02
  • see http://stackoverflow.com/questions/5905877/how-to-run-the-php-code-asynchronous/5906369# – Oliver A. Apr 02 '13 at 13:08
  • I'll keep a small cache of the content fetched from those websites, yes. The thing is: users can have many different subscriptions, and I'd need to update them every now and then. Doing so synchronously would take too long. – Pedro Cordeiro Apr 02 '13 at 13:08
  • @OliverA., this would be pretty much the same as using cURL. If I need to do this, I'd like to know what's the best practice here (doing it in my controller, in a service or in a different bundle). – Pedro Cordeiro Apr 02 '13 at 13:10
  • 3
    Guzzle allows you to do so http://guzzlephp.org/guide/batching.html – AdrienBrault Apr 02 '13 at 13:15

1 Answers1

1

I think Guzzel is the most famous library for PHP that allows you to send synchronous and asynchronous requests: https://docs.guzzlephp.org/en/stable/

A sample code of async call:

$request = new \GuzzleHttp\Psr7\Request('GET', 'YOUR_URL');
$promise = $client->sendAsync($request)->then(function ($response) {
    echo 'I completed! ' . $response->getBody();
});
AMK
  • 662
  • 6
  • 16