I have encountered an issue recently where, during periods of high traffic to my application, small CSV files are being sent with cURL/FTP with zero bytes. However, when I view the file on my filesystem I can see that it is definitely not empty and not zero bytes in size.
This is my PHP code:
$ch = curl_init();
$fp = fopen($bFile, 'r');
curl_setopt($ch, CURLOPT_URL, 'ftp://'.FTP_SERVER .'/'.FTP_DIRECTORY.$file_name);
curl_setopt($ch, CURLOPT_USERPWD, FTP_USER.':'.FTP_PASS);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($bFile));
curl_setopt($ch, CURLOPT_FTP_USE_EPSV, false);
curl_exec($ch);
I also have some basic error handling in the code where cURL returns an error:
if ( curl_error($ch) ) {
throw new Exception("File could not be sent via FTP: " . curl_error($ch));
}
However, I note in this example there is no occasion where the exception is thrown and the code execution continues.
Would there be any reason that I have a, say, a 5Kb CSV file on my filesystem, but the FTP server I am sending the file to has only a zero byte file? Does this point to a transmission issue, possibly caused by high amounts traffic at this time of year?
Since you mention its during high traffic. Is it possible that there is lots or read/write activity on the CSV files you are trying to send? Perhaps its the fopen that actually fails and thus you are sending 0 bytes, but with the correct filename. That would only generate a warning so wont be caught.
Perhaps you should add some logging to the different values you are sending with curl, like filesize($bFile)
and $fp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With