Hi all
I am hoping someone can help with this problem.
I have a system which compares a number of stockfiles from suppliers FTP servers… and depending on whether they are newer than the current data it will update our systems when needed.
The suppliers files are uploaded to our FTP server. My system stores the initial datafiles timestamp in a SQL database when it imports the data to our system, then hourly it compares the timestamp of the suppliers file to the timestamp in the SQL database… if its different it deletes that suppliers data from the Stocklist database, replaces it and updates the timestamp database with the timestamp of the newly imported data. I do this test as there are so many files, if they were all updated together it takes about 10 minutes for the script to run!
This works seamlessly and is run hourly on an Ubuntu server as a cron job.
However I have a new supplier who sends two data files, one contains their stock listings and the second contains product pricing. When I import these into the Stocklist database I have to ‘join’ data from both files.
However I want to compare the timestamps on both files and if either have changed for the update process to start. But for some reason I cannot get this to work - it always shows the timestamps as different and runs a delete & update process.
I am using identical scripts for all the other suppliers and it is faultless, so I cannot work out why this wont work
This is how I am getting the timestamp from the datafile uploaded by the supplier;
$file1_timestamp = (string)date (filemtime('/var/www/clients/client1/web1/web/distcheck/datafiles/supplier/FILE1.TXT'));
$file2_timestamp = (string)date (filemtime('/var/www/clients/client1/web1/web/distcheck/datafiles/supplier/FILE2.TXT'));
This is how I am getting the timestamp from the SQL database (which stores the timestamp of the data file when the last update took place);
$sql_supplier_file1="SELECT `timestamp` FROM `timestamp` WHERE `disti` = 'Supplier1'";
$result=mysqli_query($mysqli,$sql_supplier_file1);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
$timestamp_supplier_file1 = $row["timestamp"];
$sql_supplier_file2="SELECT `timestamp` FROM `timestamp` WHERE `disti` = 'Supplier2'";
$result=mysqli_query($mysqli,$sql_supplier_file2);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
$timestamp_supplier_file2 = $row["timestamp"];
These all work perfecty as an example, the results for these variables are;
$file1_timestamp = 1713292194
$file2_timestamp = 1713373268
$timestamp_supplier_file1 = 1713292194
$timestamp_supplier_file2 = 1713373268
So, as both the files have the same timestamp in the timestamp SQL database and the actual files, I want to compare the two and for nothing to happen… this is the formula I am using;
if (($file1_timestamp == $timestamp_supplier_file1) AND ($file2_timestamp == $timestamp_supplier_file2)) {
echo "Timestamps matches - no update required</br>";
}else{
echo "Timestamps dont match - update required</br>";
}
But, everytime the script runs, whether the timestamps match or not, I get the message that the timestamps dont match!!
I also tried this alternative script (which doesnt work!!);
if ($file1_timestamp == $timestamp_supplier_file1) {
if ($file2_timestamp == $timestamp_supplier_file2) {
echo "Timestamps match - no update required</br>";
}else{
echo "Timestamps dont match - update required</br>";
}
}else{
echo "Timestamps dont match - update required</br>";
}
Please note all timestamps are standard UNIX so they can be compared.
So, if anyone can help I would be very grateful.