2

How can I not wait for response from API call?

I have a big batch of API calls (one depends on other) but application does not need the results. Just say "Facebook do this" and do not wait for response.

How can I not wait for a response?

Jindra
  • 780
  • 13
  • 39
  • If you don't have to make the call in the backend it'll make sense to use a client-side request eg via AJAX or the JS SDK. – Ahmed Nuaman Nov 24 '11 at 23:13
  • Yes, it would work, but I am looking for server side easiest way. So send and do not care what it is doing. With AJAX server would hande more request and still wait for answer. – Jindra Nov 25 '11 at 16:06

2 Answers2

2

I believe you are looking for a way to do a async php calls. You may end up with doing some queries by yourself, as I don't think PHP FB SDK support such queries.

I believe curl_multi (php5 only) is a solution you look for:

You may also find this QA helpful:

Community
  • 1
  • 1
  • Actually i wasn't looking for async calls, i just wanted to set 'wait for response' = false and do not handle response sometime else on incoming response event. But you are right, it would work! but writing it without SDK will be difficult. I have batch request inluding file upload, but i will take a look on this solution. – Jindra Nov 25 '11 at 16:11
2

I was involved in a project a while back where we implemented queuing for something similar to this. (The application was posting to the walls of around 150 pages as well as some other data collection.

Our solution was this:

We had a Queue table that was populated with Jobs. These were made up of the parameters, token and the particular Facebook API call. The table also had a status column that was either set to scheduled/success/fail, a response column and a couple of datetime columns, scheduled & sent.

A script that looked for scheduled jobs, then ran the API calls and collected the response was run by a cron job at an arbitrary interval.

The application itself could look at the Queue table and produce a report of what jobs had been run and their responses, as well as the upcoming scheduled jobs.

Moz Morris
  • 6,681
  • 2
  • 20
  • 18
  • I think it's a briliant solution! I have just one doubt about it. When it is added to queue and user leave aplication, i will not have permission to make POST calls on his ACC. I do have to require offline acces, am i right? – Jindra Nov 25 '11 at 16:14
  • @Henry It depends on when you intend to to make the API calls. The 'standard' token issued by Facebook has a timeout associated with it (in seconds I believe). If you intend to make the API call after this timeout, then yes, you would need to request offline access. – Moz Morris Nov 25 '11 at 17:09