简体   繁体   中英

CRON Job using Curl.

I have a PHP Code, which reloads itself with another GET value. Like: example.com?number=453 and it keeps doing this for days. I was doing this in the browser. But i found cron job is way better.

So, I need to use CURL to reload the page with a new GET value like ?number=550 . So this is the code, which i use (found it on stackoverflow)

function curl_download($Url){

    // is cURL installed yet?
    if (!function_exists('curl_init')){
        die('Sorry cURL is not installed!');
    }

    // OK cool - then let's create a new cURL resource handle
    $ch = curl_init();

    // Now set some options (most are optional)

    // Set URL to download
    curl_setopt($ch, CURLOPT_URL, $Url);

    // Set a referer
    curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");

    // User agent
    curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");

    // Include header in result? (0 = yes, 1 = no)
    curl_setopt($ch, CURLOPT_HEADER, 0);

    // Should cURL return or print out the data? (true = return, false = print)
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Timeout in seconds
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);

    // Download the given URL, and return output
    $output = curl_exec($ch);

    // Close the cURL resource, and free system resources
    curl_close($ch);

    return $output;
}


$output = curl_download("http://www.example.com/yourscript.php?number='$requestsDone'");

And at the end of the page, i use this, to call the function

curl_download($Url);

But i am getting this error:

Notice: Undefined variable: Url

in the last line, ie curl_download($Url);

This is how we call the function right? What's wrong? Also is there any mistake or improvement, I can make in the code?

You not assign values ​​to variables $Url. Before you can assign values ​​to variables $Url. That like

$Url = "http://domaintest.com/?number=550";
curl_download($Url);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM