Вопрос

i have a file cron.php in it is a CURL function. The CURL function writes content from a diferent website in my database. If i call it in the browser it works fine, but in the cron jobs it write the wronge content from the site into my database.

Is there a problem between crontab and CURL in php files?

UPDATE

the curl function:

function CurlPost($sURL,$sMessage = "")
{

    $cookie_file_path = "cookies/cookies.txt";
    print_r($sMessage);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_URL, $sURL);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); 
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $sMessage);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);


    $sResult = curl_exec($ch);
    curl_close($ch);
    return $sResult;


}
Это было полезно?

Решение

You must have to provide full/absolute path for file name when running it from cron. You must be using cookie with your curl, and that is lacking of absolute path. Hence the cookie is not working and you are getting wrong content.

curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');

So cookie.txt should be /home/tmp/cookie.txt

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top