0

이것은 내 첫 번째 프로젝트는 페이스 북의 API와 페이스 북의 PHP SDK를 사용하여, 기본적으로 모든 사용자 상태를 얻으려고하고있어. 나는 작동해야하는 스크립트를 작성했는데 (최대 실행 시간을 변경하거나 제한 시간 (0)을 설정 했더라도) 500 개의 오류가 발생했지만 내부의 재귀 함수를 사용할 때만 코드를 살펴보십시오.페이 스북 api, 재귀 함수 및 500 오류

내가 기능을 기억 해달라고하면
$request = new FacebookRequest(
$session, 
'GET', 
'/me/statuses' 
); 
$response = $request->execute(); 
$graphObject = $response->getGraphObject(); 
$x = $graphObject->getProperty('data'); 
$y = $x->asArray(); //now i got an array 
$paging = $graphObject->getProperty('paging'); // i pick paging with "next" and "prevoiuos " 
$paged = $paging->asArray(); //as array 
$counter = 0 ;    
foreach ($y as $el){ 
     echo ('<h3>'.$y[$counter]->message.'</h3>'); 
     echo "<br/>"; 
     echo "<br/>"; 
     $counter++; 
} 

$next = $paged['next']; // now i got url for load 20 more statuses 
$response = file_get_contents($next); // get content of url 

//recoursive function every time i use looper with content of next 
function looper($response){ 
    $array = json_decode($response, true); 
    $secondarray = ($array['data']); 
    $paging = ($array['paging']); // again i pick url for load next statuses 
    $next = $paging['next'];// again i pick url for load next statuses 
    $nextResponse = file_get_contents($next);// again i pick url for load next  statuses and i will use this. 
    $counter2 = 0 ;    
     foreach ($secondarray as $el){ // put on page next 20 statuses 

       echo ('<h3>'. $secondarray[$counter2]['message'] .'</h3>'); 
       echo "<br/>"; 
       echo "<br/>"; 
       $counter2++; 


     } 
     if (is_null($nextResponse) == false){ // if in next call i got 20 more statuses(not empty) call again this function 
      looper($nextResponse); 
     } else { echo "last message" ; die();} //else stop. 

} 

looper($response); 

}

스크립트 잘 작동 20 개 + 20 상태를 인쇄, 다른 사람이 나에게 줄 500 내부 오류 (기본적으로 난 문이 경우 주석). 나는 최대 실행 시간 또는 set_time_limit (0)을 변경하려고했지만 아무 일도 일어나지 않는다고 말했다. 문제가 내 호스팅 (godaddy)인지 또는 스크립트가 좋지 않거나 효율적이지 않은지 잘 모르겠습니다. 어떤 도움? 감사합니다. Nico

+0

당신이 $ nextResponse의 실제 값이 더 옆에 응답이 없을 때 무엇을 볼 수 무한 재귀해야합니다 ... 당신이 –

+0

되고 싶어요 것처럼 null이되지 않을 수도 있습니다 PHP error_log에 어떤 메시지가 있습니까? – angeldelrio

+0

메시지가 없습니다. @angeldelrio –

답변

0

문제점을 찾은 것 같습니다. $nextResponse 값이 file_get_contents에 의해 반환됩니다. http://php.net/manual/es/function.file-get-contents.php을 참조하십시오. 콘텐츠를 검색 할 수 없으면 false을 반환합니다. false 대신 null의 확인하십시오 :

 .......... 

     if (false != $nextResponse){ // if in next call i got 20 more statuses(not empty) call again this function 
      looper($nextResponse); 
     } else { echo "last message" ; die();} //else stop. 
+0

고마워요! 이것이 문제였다. –

+0

그런데 if 문에서 "$ nextResponse! = false"를 사용했습니다. 왜냐하면 == 때문에 데이터가 없어도 함수를 다시 호출하기 때문입니다. –

+0

오우, 내 잘못, 내가 바로 잡는다. – angeldelrio