Scenario:
I'm working on a Xampp / Ubuntu Server web server, I needed a routine to run at least 2 times in a minute (30 seconds approximately).
To achieve this, raise a cron as follows:
* * * * * /opt/lampp/htdocs/control/cronos/cron.sh
This way the cron file was in reach of the web server and FTP and allows me to edit it in the measure.
This cron.sh file has the following code to execute a php script:
#!/bin/sh
cd /opt/lampp/htdocs/control/cronos/
php cron.php
runs every 1 min. Once the cron.php has been executed, the PHP file has the following content:
<?php
$j=0;
while($j<=1){
$url = 'http://127.0.0.1/index.php';
$fields = array(
'idprocess' => 'p-gen-cronjobs',
'idform' => 'p-gen-cronjobs',
);
// build the urlencoded data
$postvars = http_build_query($fields);
// open connection
$ch = curl_init();
// set the url, number of POST vars, POST data
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); #Update
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
// execute post
curl_exec($ch);
// close connection
curl_close($ch);
$j++;
sleep(25);
}
?>
This php code enters a loop of 25 seconds, which executes 2 request http by POST, sending the 2 variables: 'idprocess' => 'p-gen-cronjobs','idform' => 'p-gen-cronjobs'
; This happens correctly.
The problem:
is that if there is one or more users logged on the same page / platform after some time they are removed from the system, the form of login is through Sessions, I do not know how to check / locate the possible logical error, I verified that when the cron makes the requests validate the cron automatically as it was a user previously logged in (obvious by security issue only if the request was local: 127.0.0.1)
I post this Post in this section of stackoverflow since I consider it a problem in programming.