hello I have implemented a cron system for ubuntu; which for reasons that I need to run every 30 seconds I had to make some adjustments in conjunction with PHP to achieve the necessary scope.
the problem is that before the implementation everything worked fine; After the implementation I noticed that the user's php sessions are randomly deleted after 1 hour. when it should last up to 8 hours ...
CRON file executed:
#!/bin/sh
cd /opt/lampp/htdocs/control/cronos/
php cron.php
CRON PHP Handler:
<?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);
}
?>
Sistem Handler for PHP Manager Cron Execution:
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;
}
How can I avoid session problems with the cron and the multiple requests that are made using curl?