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?

5
  • Just to be clear: You want to do a http request to a specific site and store/handle the response every now and then? Commented Apr 2, 2013 at 13:02
  • see stackoverflow.com/questions/5905877/… Commented Apr 2, 2013 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. Commented Apr 2, 2013 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). Commented Apr 2, 2013 at 13:10
  • 3
    Guzzle allows you to do so guzzlephp.org/guide/batching.html Commented Apr 2, 2013 at 13:15

1 Answer 1

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();
});
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, you're correct. There's also symfony/http-request package that's also quite nice.

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.