3v4l.org

run code in 300+ PHP versions simultaneously
<?php // ************************************************************************ // Class PHPTube // Version: 0.1.3 // Date: 2007/07/01 // Author: Michael Kamleitner (michael.kamleitner@gmail.com) // WWW: http://www.kamleitner.com/code // (suggestions, bug-reports & general shouts are welcome) // Copyright: copyright 2007 - Michael Kamleitner // // This file is part of PHPTube // // PHPTube is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // PHPTube is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with PHPTube; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // ************************************************************************ require_once 'HTTP/Client.php'; require_once 'HTTP/Request.php'; require_once 'HTTP/Client/CookieManager.php'; class PHPTube { var $cookies; var $mgr; var $req; var $debug = false; var $auth = false; // Function: PHPTube ... Initialize YouTube-Object // Paramters: $username ... YouTube Accountname (if empty, upload is disabled) // $password ... YouTube Passwort (if empty, upload is disabled) // $debug ... Debug-Flag function PHPTube ($username = "", $password = "", $debug = false) { if ($username != "" && $password != "") { $url = "http://youtube.com/login?username=".$username."&password=".$password."&next=/index&current_form=loginForm&action_login=1"; $this->debug = $debug; $this->req =& new HTTP_Request($url); $this->req->addHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); $this->mgr = new HTTP_Client_CookieManager(); $response = $this->req->sendRequest(); if (PEAR::isError($response)) { echo $response->getMessage()."\n"; } else { $this->auth = true; $this->cookies = $this->req->getResponseCookies(); $success = false; foreach ($this->cookies as $c) { if ($c["name"]=="LOGIN_INFO" && $c["value"]<>"") $success = true; } if (!$success) die ("Login failed!\n"); } } } // Function: download ... Download any Video-Clip from YouTube // Paramters: $video_id ... Video-ID as given in YouTube URL (f.e. the Video at http://youtube.com/watch?v=TWZ5j-SNVKs // has the ID "TWZ5j-SNVKs" // $video_filename ... local path+filename, the video is downloaded to (check write-permissions!) function download ($video_id, $video_filename) { $url = "http://www.youtube.com/watch?v=".$video_id; $this->req =& new HTTP_Request($url); $response = $this->req->sendRequest(); if (PEAR::isError($response)) { echo $response->getMessage()."\n"; } else { $page = $this->req->getResponseBody(); preg_match('/watch_fullscreen\?video_id=(.*?)&l=(.*?)+&t=(.*?)&/', $page, $match); $url = ""; $url .= $match[1]; $url .= "&t="; $url .= $match[3]; $url = "http://www.youtube.com/get_video?video_id=".$url; if ($this->debug) print $url."\n"; $req =& new HTTP_Request($url,array ("allowRedirects"=>true, "maxRedirects"=> 99)); $req->setMethod(HTTP_REQUEST_METHOD_GET); $req->addHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); $response = $req->sendRequest(); if (PEAR::isError($response)) { //echo $response->getMessage()."\n"; print "Error: Failed to open YouTube-Source\n"; } else { if ($o = fopen ($video_filename, "w")) { fwrite($o,$req->getResponseBody()); fclose ($o); print "Download done! File: ".$video_filename."\n"; } else { print "Error: Failed to open target-file\n"; } } /* Old Dowload-Code was using fopen if ($h = fopen ($url,"r")) { if ($o = fopen ($video_filename, "w")) { while (fwrite($o,fread($h,1024))); fclose ($o); print "Download done! File: ".$video_filename."\n"; } else { print "Error: Failed to open target-file\n"; } fclose ($h); } else { print "Error: Failed to open YouTube-Source\n"; } */ } } // Function: upload ... Upload Video-Clip to YouTube // Returns: ... ID of the new Clip // Paramters: $video_filename ... local filename of the Clip which is to be uploaded // $video_title ... Video-Title (String) // $video_tags ... Tags (String, Separeator = Blank) // $video_description ... Description (String) // $video_category ... Category (2=Autos & Vehicles, 23=Comedy, 24=Entertainment, // 1=Film & Animation, 20=Gadgets & Games, 26=Howto & DIY, // 10=Music, 25=News & Politics, 22=People & Blogs, // 15=Pets & Animals, 17=Sports 19=Travel & Places) // $video_language ("DE", "EN"...) // $public (true / false) // $family (true / false) - Not Supported anymore // $friends (true / false) - Not Supported anymore function upload ($video_filename, $video_title, $video_tags, $video_description, $video_category, $video_language, $public=true, $family=true, $friends=true) { if ($this->auth) { if (file_exists($video_filename)) { $url = "http://www.youtube.com/my_videos_upload"; $this->req =& new HTTP_Request($url); $this->req->setMethod(HTTP_REQUEST_METHOD_POST); $this->req->addHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); $this->req->addPostData("field_myvideo_title",$video_title); $this->req->addPostData("field_myvideo_keywords",$video_tags); $this->req->addPostData("field_myvideo_descr",$video_description); $this->req->addPostData("language",$video_language); $this->req->addPostData("field_myvideo_categories",$video_category); $this->req->addPostData("ignore_broadcast_settings","0"); $this->req->addPostData("action_upload","1"); if ($public) { $this->req->addPostData("field_privacy","public"); } else { $this->req->addPostData("field_privacy","private"); // Seems like the Family/Friends-option isn't existing anymore //if ($family && $friends) // $this->req->addPostData("share_list","Family,Friends"); //elseif ($family) // $this->req->addPostData("share_list","Family"); //elseif ($friends) // $this->req->addPostData("share_list","Friends"); } foreach ($this->cookies as $c) { $this->mgr->addCookie ($c); } $this->mgr->passCookies ($this->req); $response = $this->req->sendRequest(); if (PEAR::isError($response)) { die ("Error: ".$response->getMessage()."\n"); } else { $p = strpos($this->req->getResponseBody(),"id=\"theForm\""); $p = strrpos(substr($this->req->getResponseBody(),0,$p),"<form"); $p = $p + strpos(substr($this->req->getResponseBody(),$p),"action=\"") + 8; $url = substr($this->req->getResponseBody(),$p,strpos(substr($this->req->getResponseBody(),$p),"\"")); $p = strpos($this->req->getResponseBody(),"name=\"addresser\" value=\""); $addresser = substr($this->req->getResponseBody(),$p+24,strpos(substr($this->req->getResponseBody(),$p+24),"\"")); if ($this->debug) { print "action: ".$url."\n"; print "addresser: ".$addresser."\n"; } $this->req =& new HTTP_Request($url); $this->req->addHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); $this->req->setMethod(HTTP_REQUEST_METHOD_POST); $this->req->addPostData("field_command","myvideo_submit"); $this->req->addPostData("field_myvideo_title",$video_title); $this->req->addPostData("field_myvideo_keywords",$video_tags); $this->req->addPostData("field_myvideo_descr",$video_description); $this->req->addPostData("language",$video_language); $this->req->addPostData("field_myvideo_categories",$video_category); $this->req->addPostData("action_upload","1"); $this->req->addPostData("addresser",$addresser); if ($public) { $this->req->addPostData("field_privacy","public"); } else { $this->req->addPostData("field_privacy","private"); //if ($family && $friends) // $this->req->addPostData("share_list","Family,Friends"); //elseif ($family) // $this->req->addPostData("share_list","Family"); //elseif ($friends) // $this->req->addPostData("share_list","Friends"); } if ($this->debug) print "file: ".$video_filename."\n"; $this->req->addFile("field_uploadfile",$video_filename); $this->mgr->passCookies ($this->req); $response = $this->req->sendRequest(); if (PEAR::isError($response)) { echo "Error: ".$response->getMessage()."\n" ; } else { if ($this->debug) print "Upload OK - ".$response."!\n"; $this->req =& new HTTP_Request("http://youtube.com/my_videos"); $this->mgr->passCookies ($this->req); $response = $this->req->sendRequest(); if (PEAR::isError($response)) { echo $response->getMessage()."\n"; } else { $p = strpos($this->req->getResponseBody(),"id=\"checkbox_"); $video_id = substr($this->req->getResponseBody(),$p+13, strpos(substr($this->req->getResponseBody(),$p+13),"\"")); print "Upload done! ID: ".$video_id."\n"; return $video_id; } } } } } else { print "Error: not authenticated!\n"; } } } ?>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
7.0.70.0130.07319.84
7.0.60.0070.08319.94
7.0.50.0070.05320.28
7.0.40.0100.08320.13
7.0.30.0130.08320.14
7.0.20.0070.08720.18
7.0.10.0100.07720.10
7.0.00.0130.08020.07
5.6.220.0100.07720.75
5.6.210.0030.08320.84
5.6.200.0100.07721.20
5.6.190.0200.06721.14
5.6.180.0130.05721.19
5.6.170.0070.05021.19
5.6.160.0030.07321.13
5.6.150.0100.08021.26
5.6.140.0070.08721.15
5.6.130.0070.05021.09
5.6.120.0230.07321.22
5.6.110.0000.06021.13
5.6.100.0130.03721.18
5.6.90.0130.07021.07
5.6.80.0070.08320.54
5.6.70.0130.07320.43
5.6.60.0100.06320.54
5.6.50.0170.04320.41
5.6.40.0130.07320.55
5.6.30.0100.07720.50
5.6.20.0070.07720.47
5.6.10.0030.04320.48
5.6.00.0130.07020.51
5.5.360.0070.07020.48
5.5.350.0070.08320.52
5.5.340.0170.07320.98
5.5.330.0070.08020.88
5.5.320.0170.07020.89
5.5.310.0100.08020.87
5.5.300.0170.07020.95
5.5.290.0130.05320.82
5.5.280.0000.08021.02
5.5.270.0130.07320.88
5.5.260.0170.04321.01
5.5.250.0070.04020.79
5.5.240.0070.08320.21
5.5.230.0070.08020.39
5.5.220.0130.07020.34
5.5.210.0200.07020.38
5.5.200.0030.08320.32
5.5.190.0170.07020.17
5.5.180.0030.06020.28
5.5.160.0030.05020.33
5.5.150.0130.07720.28
5.5.140.0070.08020.08
5.5.130.0100.07720.27
5.5.120.0100.04320.08
5.5.110.0070.07720.30
5.5.100.0100.08720.17
5.5.90.0100.08020.18
5.5.80.0030.04020.16
5.5.70.0070.06020.18
5.5.60.0070.08320.23
5.5.50.0170.03720.14
5.5.40.0130.07320.10
5.5.30.0000.05320.17
5.5.20.0200.06720.23
5.5.10.0100.06020.13
5.5.00.0070.04720.09

preferences:
145.69 ms | 1394 KiB | 7 Q