Changeset 606 for trunk/lib/Utilities.inc.php
- Timestamp:
- Jun 22, 2017 12:02:35 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Utilities.inc.php
r605 r606 1446 1446 /* 1447 1447 * Returns true if the given URL resolves to a resource with a HTTP 2xx or 3xx header response. 1448 * The download will abort if it retrieves >= 10KB of data to avoid downloading large files. 1449 * We couldn't use CURLOPT_NOBODY (a HEAD request) because some services don't behave without a GET request (ahem, BBC). 1450 * This function may not be very portable, if the server doesn't support CURLOPT_PROGRESSFUNCTION. 1448 1451 * 1449 1452 * @access public … … 1451 1454 * @return bool True if the resource exists, false otherwise. 1452 1455 * @author Quinn Comendant <quinn@strangecode.com> 1453 * @version 1.01456 * @version 2.0 1454 1457 * @since 02 May 2015 15:10:09 1455 1458 */ … … 1458 1461 $ch = curl_init($url); 1459 1462 curl_setopt($ch, CURLOPT_TIMEOUT, 5); 1460 curl_setopt($ch, CURLOPT_NOBODY, true);1461 1463 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 1462 1464 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 1465 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"); 1466 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Don't pass through data to the browser. 1467 curl_setopt($ch, CURLOPT_BUFFERSIZE, 128); // Frequent progress function calls. 1468 curl_setopt($ch, CURLOPT_NOPROGRESS, false); // Required to use CURLOPT_PROGRESSFUNCTION. 1469 curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($ch, $dltot, $dlcur, $ultot, $ulcur){ 1470 // Return a non-zero value to abort the transfer. In which case, the transfer will set a CURLE_ABORTED_BY_CALLBACK error 1471 // 10KB should be enough to catch a few 302 redirect headers and get to the actual content. 1472 return ($dlcur > 10*1024) ? 1 : 0; 1473 }); 1474 1463 1475 curl_exec($ch); 1464 1476 $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
Note: See TracChangeset
for help on using the changeset viewer.