3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $urlimdbapi='https://gdata.youtube.com/feeds/api/videos?q=Batman trailer&max-results=1&v=2.1&alt=jsonc&format=5'; $imdbapiresult=new CustomCURL($urlimdbapi, $cookie_file); $imdbresult=$imdbapiresult->send(); $imdbs_info=json_decode($imdbresult['content'], true); print_r($imdbs_info); class CustomCURL{ private $fsocket; private $header; private $method; private $postdata; private $cookie_file; public static $responseHeaders; public static $custom_curl; function __construct($url, $cookie_file){ $this->method='GET'; $this->fsocket = curl_init(); $this->setopt(CURLOPT_URL, $url); $this->setopt(CURLOPT_COOKIEFILE, realpath($cookie_file)); $this->setopt(CURLOPT_COOKIEJAR, realpath($cookie_file)); $this->setopt(CURLOPT_TIMEOUT, 0); $this->setopt(CURLOPT_RETURNTRANSFER, 1); $this->setopt(CURLOPT_MAXREDIRS, 10); $this->setopt(CURLOPT_CONNECTTIMEOUT, 30); $this->setopt(CURLOPT_FOLLOWLOCATION, 1); $this->setopt(CURLOPT_AUTOREFERER, 1); $this->setopt(CURLINFO_HEADER_OUT, 1); $this->setopt(CURLOPT_HEADER, 0); $this->setopt(CURLOPT_VERBOSE, 0); $this->setopt(CURLOPT_SSL_VERIFYPEER, 0); $this->setopt(CURLOPT_SSL_VERIFYHOST, 0); self::$responseHeaders=array(); $this->setopt(CURLOPT_HEADERFUNCTION,array('CustomCURL','headerFunction')); $this->cookie_file=$cookie_file; } static function headerFunction($ch, $header){ $vars=explode(':',$header,2); self::$responseHeaders[strtolower(trim($vars[0]))]=isset($vars[1])?trim($vars[1]):''; return strlen($header); } function setopt($opt, $value){ return curl_setopt($this->fsocket, $opt, $value); } function setHeaders($array){ return $this->header = $array; } function setPostData($array, $isMultipart = true){ $this->method='POST'; if($isMultipart){ $this->postdata = $array; }else{ $post=''; foreach($array as $key=>$val){ if(is_array($val)){ foreach($val as $subval){ if($post!=''){ $post.='&'; } $post.=urlencode($key).'='.urlencode($subval); } }else{ if($post!=''){ $post.='&'; } $post.=urlencode($key).'='.urlencode($val); } } $this->postdata = $post; } } function send($forMulti=false){ if(!empty($this->header)){ $this->setopt(CURLOPT_HTTPHEADER, $this->header); } if($this->method=='POST' && !empty($this->postdata)){ $this->setopt(CURLOPT_POST, 1); $this->setopt(CURLOPT_POSTFIELDS, $this->postdata); } if($forMulti){ return $this->fsocket; } $exec = curl_exec($this->fsocket); if(curl_errno($this->fsocket)){ $result['error'] = curl_error($this->fsocket); }else{ $result['post_data'] = $this->postdata; $result['content'] = $exec; $result['info'] = curl_getinfo($this->fsocket); $result['info']['request_headers']=curl_getinfo($this->fsocket, CURLINFO_HEADER_OUT); $result['info']['response_headers']=self::$responseHeaders; } $this->debug($result, $this->cookie_file); return $result; } function debug($result,$cookie){ /* ============================== THIS IS FOR DEBUGGING PURPOSES ============================== Comment return; to trace output */ return; echo '<h1>',$result['info']['url'],'</h1>'; echo '<h2>Content</h2>'; echo '<pre>',htmlspecialchars($result['content']),'</pre>'; echo '<h2>Cookies</h2>'; echo '<pre>',@file_get_contents($cookie),'</pre>'; echo '<h2>Post Data</h2>'; echo '<pre>'; print_r($result['post_data']); echo '</pre>'; echo '<h2>Other Info</h2>'; echo '<pre>'; print_r($result['info']); echo '</pre>'; flush(); usleep(100); } function close(){ curl_close($this->fsocket); $this->header = array(); $this->postdata = array(); } }
Output for 7.0.0 - 7.1.0
Notice: Undefined variable: cookie_file in /in/ZPtTm on line 4 Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/ZPtTm:21 Stack trace: #0 /in/ZPtTm(4): CustomCURL->__construct('https://gdata.y...', NULL) #1 {main} thrown in /in/ZPtTm on line 21
Process exited with code 255.
Output for hhvm-3.12.0
Notice: Undefined variable: cookie_file in /in/ZPtTm on line 4 Warning: realpath() expects parameter 1 to be string, null given in /in/ZPtTm on line 23 Warning: realpath() expects parameter 1 to be string, null given in /in/ZPtTm on line 24 Notice: Undefined index: content in /in/ZPtTm on line 6 Warning: json_decode() expects parameter 1 to be string, null given in /in/ZPtTm on line 6
Output for hhvm-3.10.0
Notice: Undefined variable: cookie_file in /in/ZPtTm on line 4 Notice: Undefined index: content in /in/ZPtTm on line 6
Output for 5.3.0 - 5.6.28
Notice: Undefined variable: cookie_file in /in/ZPtTm on line 4 Fatal error: Call to undefined function curl_init() in /in/ZPtTm on line 21
Process exited with code 255.