I am developing a facebook app and I have some php functions. When I call one of them, the request is sent over and over and goes in an infinite loop. I have no clue why. My function is:
function writeJSON()
{
if (!$user_id) {
echo "User not logged in";
}
else
{
global $arrayForJSON,$user_id;
$arrayForJSON['a']='b';
var_dump($arrayForJSON);
}
}
If I run it just like that, it will show
array (size=1) 'a' => string 'b' (length=1)
Which is correct. However if I run another function that adds more elements to the$arrayForJSON
, it goes into the loop. The other function is:
function getLikes()
{
global $facebook,$user_id,$arrayForJSON;
$likes=NULL;
if($user_id) {
try {
if(is_null($likes))
$likes = idx($facebook->api('/me/likes'), 'data', array());
if ($likes) {
$arrayForJSON['likes']=$likes;
}
}
catch(FacebookApiException $e){
echo error_log($e);
}
echo "done";
var_dump($arrayForJSON);
}
else
echo "Not working";
Please give a helping hand, I've been working on that for some time and I have no clue what should I do.
If I call writeJSON()
before calling getLikes()
, it works. If I call it afterwards, it goes into the loop. I obviously need to call it after calling getLikes
, because I need that data to be written to the JSON file
There is no place whatsoever where there could be any looping or recursion in both of your functions. Most likely your
getLikes()
function is being called repeatedly from somewhere else that's outside of the posted code.There is a somewhat similar question here, that suggests that Facebook authorization might be at fault somehow. I'm including the link here because maybe there is some code you're not showing that may cause the same behavior. However, it couldn't be caused just by the code you have posted.