Asynchronous php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TheStoryTeller
Forum Newbie
Posts: 15
Joined: Fri May 01, 2009 10:13 am

Asynchronous php

Post by TheStoryTeller »

Hello,
I have a problem (obviously).
I am writing a simple Facebook application which gives the user a table with basic statistics of his friends. nothing fancy.
Some users have a lot of friends. When I tested the application with some of my friends-rich friends account - I realized that since the calculation is too long, facebook is giving a standrad error message and stops.
For other friends it works fine.
This is a PHP forum so i'll cut to the chase:
In the Facebook developer forum they advised me to make my code asynchronous. that is, send some page to the user and continue the process behind the scene.
I haven't the slightest idea how to approach that. any suggestion?
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: Asynchronous php

Post by novice4eva »

I bet they were talking about "ajax", make separate CALCULATION request for each friend and when the output is ready, display it.
TheStoryTeller
Forum Newbie
Posts: 15
Joined: Fri May 01, 2009 10:13 am

Re: Asynchronous php

Post by TheStoryTeller »

novice4eva wrote:I bet they were talking about "ajax", make separate CALCULATION request for each friend and when the output is ready, display it.
I still have trouble understanding it. my native language is Java or C++. I'm very familiar with the consept of "threads of execution" is there a way of doing something like that in PHP? is that what you mean?
I don't expect anyone to give me a working code or anything, I'm very willing to learn - I just need someone to point me in the right direction...
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: Asynchronous php

Post by infolock »

PHP does not support threading, although there is a nice article on faking it.

When they tell you asynchronous though, they mean to use ajax (Asynchronous Javascript And XML).

Since you're application or facebook is bombing at x %, they are suggestion you do a step by step process kind of like pagination. Grab x amount of friends (25 for examle) and display them. After displaying, use an AJAX call to grab the next x, and repeat until all are in your hands.

There are MANY tutorials on Ajax, and ajax with PHP.

Hope this helps.
TheStoryTeller
Forum Newbie
Posts: 15
Joined: Fri May 01, 2009 10:13 am

Re: Asynchronous php

Post by TheStoryTeller »

infolock wrote:PHP does not support threading, although there is a nice article on faking it.

When they tell you asynchronous though, they mean to use ajax (Asynchronous Javascript And XML).

Since you're application or facebook is bombing at x %, they are suggestion you do a step by step process kind of like pagination. Grab x amount of friends (25 for examle) and display them. After displaying, use an AJAX call to grab the next x, and repeat until all are in your hands.

There are MANY tutorials on Ajax, and ajax with PHP.

Hope this helps.
Thanks, I'll check this Ajax situation.
TheStoryTeller
Forum Newbie
Posts: 15
Joined: Fri May 01, 2009 10:13 am

Re: Asynchronous php

Post by TheStoryTeller »

can anyone help me with an efficient way of background calculation?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Asynchronous php

Post by jaoudestudios »

I dont know if facebook will let you do it, but an easy way to achieve ajax is to use the javascript library jQuery. You'll be putting together ajax applications in minutes.
Post Reply