PHP Curl download files to handle manually synchronizing files between servers

Source: Internet
Author: User
Tags curl

There is a need for the situation as follows:

Two servers, a test server [Apache], a production server [Nginx], product editors use PHP upload in the test servers to upload products in bulk, pictures, after checking,
Can synchronize its uploaded products and pictures [packaged into a zip file] on the production server, but the production server does not accept PHP upload upload files, then can not be on the test server directly post to the formal

Server.

Temporarily think of several methods:
1. Use rsync to manually sync past, but need to configure and require PHP to execute shell commands, but I don't want to.
2. You can use the socket to transfer the data, but you need to open the port, I do not want to do so, because if you forget at the firewall open port, it will not be able to transfer
3. Test server sends signal to production server, lets production server download files from test server using PHP Curl

by comparing, or the 3rd method is more appropriate, direct the entire process of using PHP to handle, at least reduce some unnecessary maintenance trouble.

The following is the method code content for php Curl download:

Function curl_download ($testing _server_file, $local _ File) {
  $RFP = Curl_init ($testing _server_file);
  $fp = fopen ($local _file, WB);
 
  ; curl_setopt ($CP, Curlopt_file, $fp);
  curl_setopt ($CP, Curlopt_header, 0);
 
  curl_exec ($RFP);
 
  $errno = Curl_errno ($RFP);
  $errmsg = Curl_error ($ RFP);
 
  curl_close ($RFP);
  fclose ($fp); 
 
  if ($errno) {
 &nbs p;  Echo $errmsg;
    exit;
 }
}

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.