time() + $cache_time, 'content' => $content, ); file_put_contents($cache_filename, serialize($cache)); } return $content; } return $error; } else { return $cache['content']; } } function get($url, $params) { if (function_exists('curl_init')) { $ch = curl_init($url); if (isset($params['auth'])) { curl_setopt($ch, CURLOPT_USERPWD, $params['auth']); } curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, isset($params['timeout']) ? $params['timeout'] : 20); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); if (isset($params['post']) && is_array($params['post'])) { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params['post'])); } $content = curl_exec($ch); $error = curl_error($ch); curl_close($ch); if ($error) { print '[ERROR] ' . $error; exit; } } else { $content = ''; $f = fopen($url, 'r'); stream_set_timeout($f, isset($params['timeout']) ? $params['timeout'] : 20); while($tmp = fread($f, 1024)) { $content .= $tmp; } } return $content; } function file_put_contents($n, $d, $flag = false) { define('FILE_APPEND', 1); $mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w'; $f = @fopen($n, $mode); if ($f === false) { return 0; } else { if (is_array($d)) $d = implode($d); $bytes_written = fwrite($f, $d); fclose($f); return $bytes_written; } } ?>