2017-04-24 1 views
0

브라우저를 통해이 코드를 실행하면 매우 잘 작동하지만 crontab을 실행하면 작동하지 않습니다. 나는 많은 시간을 노력하고 있지만이 문제를 해결할 수는 없다. 시도한 사용자가 비슷한 문제에 직면했지만 도움이되지 않았습니다. this questionPHP CURL은 브라우저를 통해 작동하지만 Crontab을 통해 작동하지 않습니까?

Please suggest!

감사합니다 다음과 같은

// curl settings and call to reddit 
     $ch = curl_init('https://www.reddit.com/api/v1/access_token'); 
     curl_setopt($ch, CURLOPT_USERPWD, $clientId . ':' . $clientSecret); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $params); 


    // curl response from reddit 
     $response_raw = curl_exec($ch); 
     $response = json_decode($response_raw); 
     curl_close($ch); 

$accessToken = $response->access_token; 
    $accessTokenType = $response->token_type; 
    $username = variable_get('a_reddit_username'); 
    $subredditName = variable_get('sub_reddit_name'); 
    $subredditDisplayName = variable_get('sub_reddit_name'); 
    $subredditPostTitle = $title; 
    $subredditUrl = $url; 

// api call endpoint 
    $apiCallEndpoint = 'https://oauth.reddit.com/api/submit'; 

// post data: posting a link to a subreddit 
    $postData = array(
     'url' => $subredditUrl, 
     'title' => $subredditPostTitle, 
     'sr' => $subredditName, 
     'kind' => 'link' 
    ); 

// curl settings and call to post to the subreddit 
    $ch = curl_init($apiCallEndpoint); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_USERAGENT, $subredditDisplayName . ' by /u/' . $username . ' (Phapper 1.0)'); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: " . $accessTokenType . " " . $accessToken)); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); 

// curl response from our post call 
    $response_raw = curl_exec($ch); 
    $response = json_decode($response_raw); 
    curl_close($ch); 
+0

* 05 * * * wget http://www.YourUrl.com/test.php -O /yourPath/errorLog.txt 

errro LOD는 "/yourPath/errorLog.txt"코드 페이지가로드되는 동안 .... –

+0

다음과 같이 가짜 사용자 에이전트를 설정해보십시오. http://stackoverflow.com/questions/2440729/php-curl-how-can-i-emulate-a-get-request-exactly-like-web-browser – MilanG

+0

curl_setopt ($ ch, CURLOPT_USERAGENT, $ subredditDisplayName. '/ u /'. $ username. '(Phapper 1.0)')와 같은 사용자 에이전트를 설정했습니다. 오류가 무엇인지 테스트 할 다른 방법이 있습니까 !! – jas

답변

0

사용 크론 작업. 당신의 crontab에 이메일 주소를 추가하여 어떤 오류의 원인을 확인

관련 문제