Last active
August 29, 2015 14:07
Revisions
-
denchev revised this gist
Oct 28, 2014 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,8 +26,21 @@ function request($url, $cache = false) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $response = curl_exec($ch); $error = curl_error($ch); $errno = curl_errno($ch); $info = curl_getinfo($ch); if($info['http_code'] == 504 || $errno == 28) { throw new Exception("Unable to open url: " . $url); } curl_close($ch); if($cache === true) { file_put_contents($file, $response); -
denchev revised this gist
Oct 10, 2014 . 1 changed file with 31 additions and 28 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,35 +2,38 @@ function request($url, $cache = false) { $prefix = 'cache_response_'; if($cache === true) { $folder = dirname(__FILE__ ) . DIRECTORY_SEPARATOR . 'cache'; $folder = file_exists($folder) && is_writable($folder) ? $folder : '/tmp'; $file = $folder . '/' . $prefix . md5($url); if(file_exists($file)) { $response = file_get_contents($file); return $response; } } $ch = curl_init(); $agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_VERBOSE, true); $response = curl_exec($ch); if($cache === true) { file_put_contents($file, $response); } return $response; } ?> -
denchev revised this gist
Oct 9, 2014 . 1 changed file with 33 additions and 29 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,32 +1,36 @@ <?php function request($url, $cache = false) { if($cache === true) { $name = md5($url); if(file_exists('/tmp/' . $name)) { $response = file_get_contents('/tmp/'.$name); return $response; } } $ch = curl_init(); $agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_VERBOSE, true); $response = curl_exec($ch); if($cache === true) { $name = md5($url); file_put_contents('/tmp/' . $name, $response); } return $response; } ?> -
denchev created this gist
Oct 9, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ function request($url, $cache = false) { if($cache === true) { $name = md5($url); if(file_exists('/tmp/' . $name)) { $response = file_get_contents('/tmp/'.$name); return $response; } } $ch = curl_init(); $agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_VERBOSE, true); $response = curl_exec($ch); if($cache === true) { $name = md5($url); file_put_contents('/tmp/' . $name, $response); } return $response; }