PHP 3 ways to download remote files and performance Considerations _php Tutorial

Source: Internet
Author: User
Today in the export of Excel, always to test the exported Excel file, frequent download and open, very troublesome to write a segment code one GO server export excel==> download Excel file to local ==> and open the operation. Here is the solution to download the remote file from PHP for forgetting. The 3rd approach takes into account performance issues when the file is too large. 3 options:-rw-rw-r--1 Liuyuan liuyuan 470 Feb 18:12 test1_fopen.php-rw-rw-r--1 Liuyuan liuyuan 541 Feb 18:06 test2_cur l.php-rw-rw-r--1 Liuyuan Liuyuan 547 Feb 18:12 test3_curl_better.php Scenario 1, for small files directly using fopen ()/file_get_contents () Get the file stream and write it with file_put_contents () Scenario 2: Get content through curl 1th, there is a problem with 2 scenarios, that is, before writing to the local disk, the file is read into memory, then when the file is large, it may crash out of memory, even if your memory settings are large enough, then this is not a cost The workaround is to give curl a writable file stream to solve this problem by itself (via the curlopt_file option) so that a file pointer is created first.   

http://www.bkjia.com/PHPjc/735879.html www.bkjia.com true http://www.bkjia.com/PHPjc/735879.html techarticle today in the export of Excel, always to test the exported Excel file, frequent download and open, very troublesome to write a segment code one GO server export excel== download Excel file ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.