| | 695 | function wp_limited_curl($url) { |
| | 696 | /* This function is a wrapper for curl |
| | 697 | * that limits the amount of data we |
| | 698 | * fetch from a URI to avoid DOS problems |
| | 699 | * with wp_remote_fopen() |
| | 700 | */ |
| | 701 | |
| | 702 | $ch = curl_init($url); |
| | 703 | global $total; |
| | 704 | global $output; |
| | 705 | $total = 0; |
| | 706 | $output = ""; |
| | 707 | |
| | 708 | function read_body($ch, $string) { |
| | 709 | $length = strlen($string); |
| | 710 | global $total; |
| | 711 | global $output; |
| | 712 | $total += $length; |
| | 713 | $output .= $string; |
| | 714 | if ($total > 30720) return -1; |
| | 715 | return $length; |
| | 716 | } |
| | 717 | |
| | 718 | curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'read_body'); |
| | 719 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); |
| | 720 | curl_setopt($ch, CURLOPT_TIMEOUT, 30); |
| | 721 | curl_setopt($ch, CURLOPT_BUFFERSIZE, 4096); |
| | 722 | curl_setopt($ch, CURLOPT_RANGE, "0-30720"); |
| | 723 | curl_exec($ch); |
| | 724 | curl_close($ch); |
| | 725 | |
| | 726 | return $output; |
| | 727 | } |
| | 728 | |
| 717 | | $handle = curl_init(); |
| 718 | | curl_setopt ($handle, CURLOPT_URL, $uri); |
| 719 | | curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 1); |
| 720 | | curl_setopt ($handle, CURLOPT_RETURNTRANSFER, 1); |
| 721 | | curl_setopt ($handle, CURLOPT_TIMEOUT, $timeout); |
| 722 | | $buffer = curl_exec($handle); |
| 723 | | curl_close($handle); |
| 724 | | return $buffer; |
| | 757 | return wp_limited_curl($uri); |