我想在我的服务器上使用cron每分钟处理一个脚本,但我需要在URL或其他方式传递变量。我已经研究了这个,并且我已经看到了在cron中使用参数的解决方案,但我不认为这与我正在做的事情有关。
以下是我要做的事情:
script.php(每分钟运行一次)
<?php
$marker = $_GET['marker'];
$accountObj = new etAccounts($consumer);
$request_params = new TransactionHistoryRequest();
$request_params->__set('count', 50); //how many will be shown
if($marker_get != ''){
$request_params->__set('marker', $marker_get); //starting point ex. 14293200140265
}
$json = $accountObj->GetTransactionHistory($account, $request_obj, $request_params );
echo $json; //shows most recent 50 transactions starting from marker value
//process json data here...
//included in json is a marker variable that will be used to return the next 50 json results
//after data is processed reload the page with marker in URL
header('Location: script.php?marker=14293200140265');
?>
我知道cron是服务器端的CLI,它无法处理重定向或标头位置,但这怎么可能。我看到有人提到使用CURL,这有什么用呢?实施例
答案 0 :(得分:0)
将post变量发送到url的简单示例:
$fields = array(
'id' => $id,
'mail' => $mail,
);
$url = "yourdomain.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
答案 1 :(得分:0)
根据评论,您不需要重定向或使用查询变量。
您可以使用在marker
变量不为空时运行的循环:
$your_marker_variable = '';
do {
$accountObj = new etAccounts($consumer);
$request_params = new TransactionHistoryRequest();
$request_params->__set('count', 50); //how many will be shown
if($marker_get != '') {
$request_params->__set('marker', $marker_get); //starting point ex. 14293200140265
}
$json = $accountObj->GetTransactionHistory($account, $request_obj, $request_params );
echo $json; //shows most recent 50 transactions starting from marker value
//process json data here...
//included in json is a marker variable that will be used to return the next 50 json results
// set the new value of $your_marker_variable
$your_marker_variable = ...
} while (!empty($your_marker_variable));
请注意,您发布的脚本中的未定义和未使用的变量使得很难看到哪些变量用于什么,因此您需要稍微调整一下。