Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading large file from remote server using php script

I am trying to read large files lets say illustrator file or photoshop file using cron job in my system. Files size varies from 20 mb - 300 mb

I have been using some function but it break in middle while reading. So i wanted to have a fresh opinion.

Amount these function

  • file_get_contents
  • readfile
  • curl

which is most effective in terms of

  • consistency (should not break while reading file)
  • speed
  • resource uses

if there is more then two cron job, does it impact over all server performance.

Please share best practice code.

Thanks in advance

like image 453
Pramendra Gupta Avatar asked Aug 29 '26 03:08

Pramendra Gupta


1 Answers

Use cURL. The file functions have been deprecated in favor of cURL to open remote files. It's not only faster, but also more reliable1 (you are less likely to experience timeouts).

If your script times out or runs out of memory anyways, you'll want to increase the execution time and memory limits (max_execution_time and memory_limit).

Other notes:

  • readfile() reads a file and prints it to the output buffer; it's no the same thing as file_get_contents().
  • If you compile curl with --with-curlwrappers then when you do file_get_contents() it will use cURL instead of the fopen() functions.

1 Citation needed.

like image 112
NullUserException Avatar answered Aug 30 '26 20:08

NullUserException



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!