0

I'm writing an app that makes a daily post as a user, and having benchmarked the PHP code that does this, it seems to take about two seconds per user. I'm dividing the work up in to chunks, and using multiple cron jobs to do each chunk. I'd like to scale to many thousands of users one day, but this kind of work load is just too much. It would take my server literally all day to post to each user one at a time using this method.

How do people normally do this? I've seen other apps that do it. Is there some way of sending all these posts off at once using just one API call? Using individual API calls per user is crazy slow.

Thanks.

ybakos
  • 8,152
  • 7
  • 46
  • 74
Duncan Marshall
  • 530
  • 1
  • 6
  • 15

2 Answers2

0

On one hand, this is entirely dependent on the API.

However, you could use a multi-threaded or pseudo-parallel approach to this, such that your program sends, say, 100 HTTP POST requests at a time, rather than generating one request after another in series.

Since you're using PHP, multi-threading is out (I think) but this question is very similar to others. For example, see how these folks recommend curl_multi.

Community
  • 1
  • 1
ybakos
  • 8,152
  • 7
  • 46
  • 74
0

You can use batch query to achieve what you need.

The code for batch query is mentioned below. You can refer more about Facebook batch query at : http://25labs.com/tutorial-post-to-multiple-facebook-wall-or-timeline-in-one-go-using-graph-api-batch-request/

$body = array(
        'message'        => $_POST['message'],
        'link'           => $_POST['link'],
        'picture'        => $_POST['picture'],
        'name'           => $_POST['name'],
        'caption'        => $_POST['caption'],
        'description'    => $_POST['description'],
        );

$batchPost[] = array(
    'method' => 'POST',
    'relative_url' => "/{ID1}/feed",
    'body' => http_build_query($body) );
$batchPost[] = array(
    'method' => 'POST',
    'relative_url' => "/{ID2}/feed",
    'body' => http_build_query($body) );
$batchPost[] = array(
    'method' => 'POST',
    'relative_url' => "/{ID3}/feed",
    'body' => http_build_query($body) );

$multiPostResponse = $facebook->api('?batch='.urlencode(json_encode($batchPost)), 'POST');
Tebe Tensing
  • 1,286
  • 9
  • 10