| | 664 | function wp_limited_curl($url) { |
| | 665 | /* This function is a wrapper for curl |
| | 666 | * that limits the amount of data we |
| | 667 | * fetch from a URI to avoid DOS problems |
| | 668 | * with wp_remote_fopen() |
| | 669 | */ |
| | 670 | |
| | 671 | $ch = curl_init($url); |
| | 672 | global $total; |
| | 673 | global $output; |
| | 674 | $total = 0; |
| | 675 | $output = ""; |
| | 676 | |
| | 677 | function read_body($ch, $string) { |
| | 678 | $length = strlen($string); |
| | 679 | global $total; |
| | 680 | global $output; |
| | 681 | $total += $length; |
| | 682 | $output .= $string; |
| | 683 | if ($total > 30720) return -1; |
| | 684 | return $length; |
| | 685 | } |
| | 686 | |
| | 687 | curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'read_body'); |
| | 688 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); |
| | 689 | curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
| | 690 | curl_exec($ch); |
| | 691 | curl_close($ch); |
| | 692 | |
| | 693 | return $output; |
| | 694 | } |
| | 695 | |
| 686 | | $handle = curl_init(); |
| 687 | | curl_setopt ($handle, CURLOPT_URL, $uri); |
| 688 | | curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 1); |
| 689 | | curl_setopt ($handle, CURLOPT_RETURNTRANSFER, 1); |
| 690 | | curl_setopt ($handle, CURLOPT_TIMEOUT, $timeout); |
| 691 | | $buffer = curl_exec($handle); |
| 692 | | curl_close($handle); |
| 693 | | return $buffer; |
| | 724 | return wp_limited_curl($uri); |