fork download
  1. <?php
  2.  
  3. /*
  4. * Download the content of a webpage or URL using PHP and cURL
  5. * http://c...content-available-to-author-only...s.com/blog/2017/05/05/download-the-content-of-a-webpage-or-url-using-php-and-curl/
  6. */
  7.  
  8.  
  9. /*
  10. * get the data from a specified URL
  11. * @param - url
  12. * @return $data - array data & info object;
  13. */
  14. function get_url_content($url) {
  15. $ch = curl_init();
  16. // set webpage url
  17. curl_setopt($ch, CURLOPT_URL, $url);
  18. // Returns TRUE on success or FALSE on failure. However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure.
  19. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  20. // The number of seconds to wait while trying to connect. Use 0 to wait indefinitely.
  21. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  22. $data = curl_exec($ch);
  23. // get curl info
  24. $info = curl_getinfo($ch);
  25. curl_close($ch);
  26. // return
  27. return array(
  28. 'data' => $data,
  29. 'info' => $info
  30. );
  31. }
  32.  
  33.  
  34. /* Get request content */
  35. $returned_content = get_url_content("http://w...content-available-to-author-only...e.be");
  36. var_dump($returned_content);
  37.  
  38. ?>
Success #stdin #stdout 0.01s 154688KB
stdin
Standard input is empty
stdout
array(2) {
  ["data"]=>
  bool(false)
  ["info"]=>
  array(26) {
    ["url"]=>
    string(51) "http://w...content-available-to-author-only...e.be/"
    ["content_type"]=>
    NULL
    ["http_code"]=>
    int(0)
    ["header_size"]=>
    int(0)
    ["request_size"]=>
    int(0)
    ["filetime"]=>
    int(-1)
    ["ssl_verify_result"]=>
    int(0)
    ["redirect_count"]=>
    int(0)
    ["total_time"]=>
    float(8.5E-5)
    ["namelookup_time"]=>
    float(0)
    ["connect_time"]=>
    float(0)
    ["pretransfer_time"]=>
    float(0)
    ["size_upload"]=>
    float(0)
    ["size_download"]=>
    float(0)
    ["speed_download"]=>
    float(0)
    ["speed_upload"]=>
    float(0)
    ["download_content_length"]=>
    float(-1)
    ["upload_content_length"]=>
    float(-1)
    ["starttransfer_time"]=>
    float(0)
    ["redirect_time"]=>
    float(0)
    ["redirect_url"]=>
    string(0) ""
    ["primary_ip"]=>
    string(0) ""
    ["certinfo"]=>
    array(0) {
    }
    ["primary_port"]=>
    int(0)
    ["local_ip"]=>
    string(0) ""
    ["local_port"]=>
    int(0)
  }
}