0

I use WinSCP to continuously retrieve CSV files from a remote FTP

I created a PHP script that scans folder every 10 minutes in order to import these CSV files into a database using a LOAD DATA INFILE

The problem is that my PHP script does LOAD DATA INFILE even if the file is still being downloaded by WinSCP (some files are 1 to 2gb, so sometimes it takes a long time)

So I would like to add a condition before the LOAD DATA INFILE to check if the CSV file is locked for modification by another user (this is what Excel tells me when I try to open it manually)

I tried several things:

is_file($file_path) 
boolean true
is_writable($file_path)
boolean true
is_readable($file_path)
boolean true
file_exists($file_path)
boolean true

When I use a fopen it gives me a false return

fopen($file_path, "r+")
boolean false

But I have an exception and I don't know if opening 2gb files before each LOAD DATA INFILE will not lower the performance of the script

Warning: fopen(***\booking.csv): failed to open stream: Resource temporarily unavailable in ***\load.php on line 62
Rocstar
  • 1,427
  • 3
  • 23
  • 41
  • fopen does not read the file into memory, it should not significantly lower the performance of your script. – Rob Ruchte Sep 02 '20 at 13:08

1 Answers1

0

I would suggest you to download the files to another folder, moving them to the monitored folder only once the download completes.

Or why don't you trigger your PHP script explicitly, once the download completes?


For a similar question, see also How to detect that a file is being uploaded over FTP.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992