你好,我已经为ubuntu实现了一个cron系统;由于我需要每30秒运行一次的原因,我不得不结合PHP进行一些调整,以达到必要的范围。
问题是,在实施之前,一切都很顺利;在实现之后,我注意到用户的php会话在1小时后被随机删除。当它应该持续8小时。。。
已执行CRON文件:
#!/bin/sh
cd /opt/lampp/htdocs/control/cronos/
php cron.php
CRON PHP处理程序:
<?php
$j = 0;
while ($j <= 1) {
$url = 'http://127.0.0.1/index.php';
$fields = array(
'idprocess' => 'p-cronjobs',
'idform' => 'p-cronjobs',
);
$postvars = http_build_query($fields);
$COOKIE_FILE_PATH = "/tmp/cookiescron.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));
curl_exec($ch);
curl_close($ch);
$j++;
sleep(25);
}
?>
用于PHP Manager Cron执行的Sistem处理程序:
switch ($idform) {
case "p-cronjobs":
$stmtpre = "SELECT TListIdCJ FROM ListCronJobs WHERE TListCJST=1 AND TListCJSTR=0;";
$data = $this->DBMANAGER->BDquery($stmtpre, DB_N_LIST);
$result_exist = $data->num_rows;
if ($result_exist != 0) {
while ($row = mysqli_fetch_assoc($data)) {
$fields = array(
'idprocess' => $row['TListIdCJ'],
'idform' => 'p-runcronjobs',
);
$postvars = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, LOCALURL);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));
curl_exec($ch);
curl_close($ch);
}
}
break;
}
如何避免cron和使用curl发出的多个请求出现会话问题?