【发布时间】:2017-07-07 12:09:03
【问题描述】:
我有一个 PHP 代码,它使用另一个 GET 值重新加载自己。像:example.com?number=453 并且它持续这样做了好几天。我在浏览器中这样做。但我发现 cron 工作要好得多。
所以,我需要使用 CURL 重新加载带有新 GET 值(例如 ?number=550)的页面。所以这是我使用的代码(在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'");
在页面的最后,我用这个来调用函数
curl_download($Url);
但我收到此错误:
注意:未定义变量:Url
在最后一行,即curl_download($Url);
这就是我们调用函数的方式对吗?怎么了?还有什么错误或改进,我可以在代码中做吗?
【问题讨论】:
-
$requestsDone来自哪里?而且它真的不需要用单引号括起来。 -
它来自代码中的某个地方,兄弟。它不是一个空变量