3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); ini_set('display_errors', 'On'); include ("../../conf.php"); error_reporting(-1); ini_set('display_errors', 'On'); $dblink = mysql_connect($DB_HOST, $DB_USER, $DB_PASS); if(!$dblink) { } mysql_select_db($dbname); function clean($str){ return mysql_real_escape_string($str); } function extract_numbers($string){ preg_match_all('/([\d]+)/', $string, $match); return $match[0]; } /* Get settings from the Database*/ $sql = mysql_query("SELECT * FROM ".PRFX."EMAIL_CONNECTOR_SETTINGS"); $sql=mysql_fetch_array($sql); $eml_server=$sql['EMAIL_SERVER']; $eml_server_port=$sql['EMAIL_SERVER_PORT']; $eml_con_type=$sql['CONNECTION_TYPE']; $eml_account=$sql['EMAIL_ACCOUNT']; $eml_account_uname=$sql['EMAIL_ACCOUNT_USERNAME']; $eml_account_pword=$sql['EMAIL_ACCOUNT_PASSWORD']; $eml_service_control=$sql['SERVICE_CONTROL']; $eml_en_flood_control=$sql['ENABLE_EMAIL_FLOOD_CONTROL']; $eml_flood_control=$sql['EMAIL_FLOOD_CONTROL']; $eml_from=$sql['FETCH_EMAIL_FROM']; /* Assign mailbox credentials */ $hostname = "{{$eml_server}:$eml_server_port/$eml_con_type}$eml_from"; $username = "$eml_account_uname"; $password = "$eml_account_pword"; if($eml_service_control =="1"){ /* try to connect to the mailbox*/ $inbox = $connection = imap_open($hostname,$username,$password) or die('Cannot connect: ' . imap_last_error()); } elseif($eml_service_control =="0") { echo 'Email to Tickets Service has been disabled by the system Administrator'; } /* If all goes well then let us grab the emails */ $emails = imap_search($inbox,'UNSEEN'); /* if emails are returned, cycle through each... */ if($emails) { /* begin output var */ $output = ''; /* put the newest emails on top */ rsort($emails); /* Process Each email Seperately */ foreach($emails as $email_number){ /*Set Flood Control if($eml_en_flood_control==1 && $fetch_eml==$eml_flood_control){ die(); }elseif($eml_en_flood_control==0 && $fetch_eml=="15"){die();}*/ $overview = imap_fetch_overview($inbox,$email_number,0); $message = imap_fetchbody($inbox,$email_number,2); $seen=$overview[0]->seen; $rep_date= date('D, d M Y - h:i A', strtotime($overview[0]->date)); $date=$overview[0]->date; $date2=$overview[0]->udate; $from_email=imap_rfc822_parse_adrlist($overview[0]->from, 'localhost');$from_email=$from_email[0]; $from_email=clean($from_email->mailbox."@".$from_email->host); $subject=clean($overview[0]->subject); $eml_subject=$overview[0]->subject; preg_match("/Ticket#([0-9]+)/", $eml_subject, $res); $wo_id=extract_numbers($overview[0]->subject); $wo_id=$wo_id[0]; $wo_id=clean($res[1]); if(!$wo_id){ $wo_id="";} libxml_use_internal_errors(true); require_once 'JSLikeHTMLElement.php'; $doc = new DOMDocument(); $doc->registerNodeClass('DOMElement', 'JSLikeHTMLElement'); $doc->loadHTML($message); //$elem = $doc->getElementById('closed_bus_wo')->item(0); $elem = $doc->getElementsByTagName('section')->item(0); $elem->innerHTML = '<!-- template replaced -->'; $message= $doc->saveXML(); $message=strip_tags($message, "<br><p><u><span><hr>"); $message=preg_replace("/(<br\ ?\/?>)+/", "<br/>", $message); $message=preg_replace( "/\s+/", " ", $message ); $message=nl2br($message); $message=clean("<br/><hr><u>Received On $rep_date / $from_email</u><br/>$message"); $message = str_replace('=', '', $message); /* Check if customer exists and get the ID*/ $q=mysql_query("SELECT * FROM `".PRFX."TABLE_CUSTOMER` WHERE CUSTOMER_EMAIL='$from_email'"); if(mysql_num_rows($q)==1){ $customer_id=mysql_fetch_array($q); $customer_id=$customer_id['CUSTOMER_ID']; } else { $customer_id=""; } /* Check for Blacklist Emails*/ $p=mysql_query("SELECT * FROM ".PRFX."EMAIL_CONTROL WHERE BLACKLIST_EMAIL='$from_email'"); $blacklist=mysql_num_rows($p); /* Assign the customer ID to the Work order*/ $r=mysql_query("SELECT * FROM ".PRFX."TABLE_WORK_ORDER WHERE WORK_ORDER_ID='$wo_id'") or die(mysql_error()); $n=mysql_num_rows($r); $r=mysql_fetch_array($r); $wo_status=$r['WORK_ORDER_CURRENT_STATUS']; $date2=date("H:i:s", $date2); $priority="1"; /*Insert work order if a customer is found*/ if($customer_id!=0 && $n==0 && $blacklist==""){ mysql_query("INSERT INTO `".PRFX."TABLE_WORK_ORDER` (WORK_ORDER_SCOPE, WORK_ORDER_DESCRIPTION, PRIORITY_ID, CREATED_TIME, WORK_ORDER_OPEN_DATE, WORK_ORDER_CURRENT_STATUS, CUSTOMER_ID) VALUES ('$subject', '$message','$priority', '$date2', '$date', '0', '$customer_id')"); /*Insert work order if no customer is found*/ } elseif($customer_id==0 && $n==0 && $blacklist=="") { mysql_query("INSERT INTO `".PRFX."TABLE_WORK_ORDER` (WORK_ORDER_SCOPE, WORK_ORDER_DESCRIPTION, PRIORITY_ID, CREATED_TIME, WORK_ORDER_OPEN_DATE, WORK_ORDER_CURRENT_STATUS, TEMP_EMAIL_ADDRESS, TEMP_EMAIL_NAME) VALUES ('$subject', '$message','$priority', '$date2', '$date', '0', '$from_email', '$from_email')"); } $new_wo_id = $db->Insert_ID(); /*IF Work order is found and not closed then, update it's description'*/ if($n==1 && $wo_status!=6) { mysql_query("UPDATE ".PRFX."TABLE_WORK_ORDER SET WORK_ORDER_DESCRIPTION = CONCAT('$message',WORK_ORDER_DESCRIPTION) WHERE WORK_ORDER_ID='$wo_id'"); /*Update and Chaange Closed Work Orders Status to Reopen*/ } elseif($n==1 && $wo_status==6) { mysql_query("UPDATE ".PRFX."TABLE_WORK_ORDER SET WORK_ORDER_DESCRIPTION = CONCAT('$message',WORK_ORDER_DESCRIPTION), WORK_ORDER_CURRENT_STATUS =11 WHERE WORK_ORDER_ID='$wo_id'") or die(mysql_error()); } if($n==1){ $existing=true; } /*Get Attachments*/ $message_number=$email_number; $structure = imap_fetchstructure($inbox, $email_number); $attachments = array(); if(isset($structure->parts) && count($structure->parts)) { for($i = 0; $i < count($structure->parts); $i++) { $attachments[$i] = array( 'is_attachment' => false, 'filename' => '', 'name' => '', 'attachment' => '' ); if($structure->parts[$i]->ifdparameters) { foreach($structure->parts[$i]->dparameters as $object) { if(strtolower($object->attribute) == 'filename') { $attachments[$i]['is_attachment'] = true; $attachments[$i]['filename'] = $object->value; } } } if($structure->parts[$i]->ifparameters) { foreach($structure->parts[$i]->parameters as $object) { if(strtolower($object->attribute) == 'name') { $attachments[$i]['is_attachment'] = true; $attachments[$i]['name'] = $object->value; } } } if($attachments[$i]['is_attachment']) { $attachments[$i]['attachment'] = imap_fetchbody($connection, $message_number, $i+1); if($structure->parts[$i]->encoding == 3) { // 3 = BASE64 $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']); } elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']); } } } } foreach($attachments as $a){ if($a['is_attachment']==1){ $filename=$a['filename']; $raw_data=$a['attachment']; if($existing) { $woid=$wo_id; } else { $woid=$new_wo_id; } // Get Recent Attachment number $q = mysql_query("SELECT * FROM `".PRFX."TABLE_WORK_ORDER_ATTACHMENTS` WHERE WO_ID='".$woid."' ORDER BY ATTACHMENT_ID DESC") or echo(mysql_error()); $rs=mysql_fetch_array($q); $a_n=$rs['ATTACHMENT_NUMBER']; if($a_n!=0){ $recent_attachment = $rs['ATTACHMENT_NUMBER']+1; } else { $recent_attachment=1; } //This is the directory where Files will be saved $target = "../../upload/message_store/".$woid."_".$recent_attachment."_"; $target = $target . basename( $filename ); //This gets all the other information from the form $date=date('Y-m-d'); $file=basename($filename); //Writes the information to the database mysql_query("INSERT INTO `".PRFX."TABLE_WORK_ORDER_ATTACHMENTS` VALUES ('$id', '$recent_attachment', '$date', '$woid', '$file' , '$file' , '$login_id')") ; //Writes the File to the server if(file_put_contents($target, $raw_data)) { //Tells you if its all ok echo "The file ". basename( $filename ). " has been uploaded to $target, and information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem saving file."; } } } /*Flag the email as Read to prevent reinsert*/ $status = imap_setflag_full($inbox, $email_number, "\\Seen \\Flagged", ST_UID); /*Delete the email from the inbox*/ imap_delete($inbox, $email_number); $fetch_eml++; } echo $output; } else { echo "<!-- debug -->"; } /* close the connection */ imap_close($inbox); ?>

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)
5.4.290.2970.04319.25
5.4.280.2970.04019.15
5.4.270.3230.04019.01
5.4.260.3300.04019.14
5.4.250.3370.03019.09
5.4.240.3070.03319.16
5.4.230.3130.03719.32
5.4.220.3300.04319.00
5.4.210.3030.03319.09
5.4.200.3070.03319.33
5.4.190.3300.03719.07
5.4.180.3170.03719.13
5.4.170.3900.04319.08
5.4.160.2930.04318.86
5.4.150.3330.04019.30
5.4.140.2970.04016.46
5.4.130.3030.03316.56
5.4.120.3070.03316.38
5.4.110.3000.03716.59
5.4.100.3270.03716.42
5.4.90.2970.04016.59
5.4.80.3300.04316.31
5.4.70.2970.03016.57
5.4.60.3130.02716.54
5.4.50.2970.04016.61
5.4.40.3200.03716.58
5.4.30.3000.03716.39
5.4.20.3330.03716.53
5.4.10.3300.03316.56
5.4.00.3370.03715.99
5.3.280.3300.04014.65
5.3.270.3030.04314.76
5.3.260.3270.04014.76
5.3.250.3000.04014.73
5.3.240.3270.04014.68
5.3.230.3270.04314.64
5.3.220.3100.03014.56
5.3.210.3300.04014.54
5.3.200.3300.03314.63
5.3.190.3300.03714.69
5.3.180.3300.03714.68
5.3.170.3130.04714.64
5.3.160.3300.03714.55
5.3.150.3000.04314.86
5.3.140.2730.03314.75
5.3.130.3230.02314.67
5.3.120.3330.03314.63
5.3.110.3300.03714.54
5.3.100.3200.04314.19
5.3.90.3030.03714.01
5.3.80.3330.03314.09
5.3.70.3270.03714.07
5.3.60.3100.04014.16
5.3.50.3270.03714.03
5.3.40.2770.03713.95
5.3.30.3370.03013.91
5.3.20.3030.03313.68
5.3.10.3270.04013.75
5.3.00.3070.03713.79

preferences:
140.82 ms | 1398 KiB | 7 Q