3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * class.MarsImportToSsi.php * * CreatedBy: dbuchanan@cotterweb.net * CreatedOn: 4/3/15 * * Requires: _classes/class.MarsLogger.php * * Handles: * 1. sending members to SSI via import web service * 2. maintains/updates db tables ssi_member_list and ssi_member_list_prev * 3. Retrieve SSI demographics (called features) * 4. Pulls ssi and cw question/answer matches from id.survey_partner_xref * */ require_once '_classes/class.MarsLogger.php'; require_once '_classes/class.DbConnectionETL.php'; /* ------------------------------------------------------------- */ /* * Child class with SSI specific id */ /* ------------------------------------------------------------- */ class SSI extends MarketResearch_logger { private $partner_id = 10; //Dev might be different then prod, could be different between SE and IBD as well function __construct($name,$debug,$env,$site,$type) { $this->setDebug($debug); $this->initLog($name); $this->env = $env; $this->site = $site; $this->type = $type; } public function getType() { return $this->type; } public function getPartnerID() { return $this->partner_id; } } /* ------------------------------------------------------------- */ /* * For talking to SSI's import api, requires instance of SSI passed in */ /* ------------------------------------------------------------- */ ///This function is used one time to pull out unique IDS, required to be this way because of quirky 5.2 bug with array_map ///PHP 5.2 doesn't like anonymous functions function tmp_get_ids($element){ return $element['respondentID']; } class SSI_api { private $ibd_source_id = '694_1264'; private $se_source_id = '694_1266'; private $batch = 100; //number of members to send in a bulk validate/submit batch private $timeout = 1500; private $qa_url = 'https://qaproxy.surveysampling.com/partner/saas/importsvc/'; // qa private $prod_url = 'https://dkr1.ssisurveys.com/partner/saas/importsvc/'; private $base_url; private $url_context; private $ob; private $country = 'US'; private $language = 'en'; private $username = 'vnd_inboxdollars'; private $password = 'pRv\'cX2*'; private $context; function __construct(SSI $ssi) { $this->ssi = $ssi; $this->base_url = ($ssi->getEnv()=='live') ? $this->prod_url : $this->qa_url; } private function createContext($ob,$type) { $credentials = "$this->username:$this->password"; $content_type = "Content-Type: application/json"; $creds = "Authorization: Basic ". base64_encode("$credentials"); $opts = array( 'http'=> array( 'method'=>$type, 'header'=>array($content_type,$creds), 'timeout'=> $this->timeout ) ); if(isset($ob)) { $opts['http']['content']=$ob; $this->ob=$ob; } else { $this->ob=''; } ////$this->ssi->logComment("Options to send: ".$ob); $this->context = stream_context_create($opts); } private function makeRequest($url) { $this->ssi->logComment("Post request ".$url); try { $result = file_get_contents($url,false,$this->context); } catch (Exception $e) { $this->ssi->logComment($e); $this->ssi->sendEmailAlert($e); } if($result===false) { $this->ssi->logComment("Request failed for $url"); $this->ssi->sendEmailAlert("Request failed for $url"); $this->ssi->addFinishComment("Failed...$url..".$this->ob); } return $result; } private function getKey() { if($this->ssi->getSite()=='inboxdollars') return $this->ibd_source_id; else if($this->ssi->getSite()=='sendearnings') return $this->se_source_id; else { $this->ssi->logComment("No api key for this, ".$this->getEnv()); $this->ssi->sendEmailAlert("No api key for this, ".$this->getEnv()); die; } } public function getBatchCount() { return $this->batch; } public function getLanguage() { return $this->language; } public function getCountry() { return $this->country; } public function getConfig() { $this->createContext(null,'GET'); return json_decode($this->makeRequest($this->base_url.'config?sourceID='.$this->getKey().'&country='.$this->getCountry().'&language='.$this->getLanguage())); } public function validateBulk($json) { $this->createContext($json,'POST'); return json_decode($this->makeRequest($this->base_url.'validate/bulk'),true); } public function submitBulk($json) { $this->createContext($json,'POST'); return json_decode($this->makeRequest($this->base_url.'submit')); } public function sendBatch($members,$features) { $this->ssi->logComment("Batch...".count($members)); $final=array('sourceId'=>$this->getKey(),'language'=>$this->getLanguage(),'country'=>$this->getCountry(),'features'=>$features,'respondents'=>$members); $json_final = json_encode($final); $validations=$this->validateBulk($json_final); $this->ssi->logComment("Validations has ".count($validations)." errors."); ///IF there are records in validations returned, that means there are problems ///Simply remove those members and log it if(count($validations) !== 0) { $this->ssi->logComment("Validation errors are..."); $this->ssi->logComment(json_encode($validations)); $this->ssi->addFinishComment("Validation errors=".count($validations).".data>>>.".json_encode($validations)); ///Need to remove those who aren't validated and log them $valid_members = array(); $bad_members = array(); ///Pull out just the IDs $invalid_member_ids = array_map("tmp_get_ids", $validations); for($x=0; $x<count($members); $x++) { if(!in_array($members[$x]['respondentID'],$invalid_member_ids)) { array_push($valid_members,$members[$x]); } else { array_push($bad_members,$members[$x]); } } $final['respondents']=$valid_members; $json_final = json_encode($final); } ///Submit members if there are some if(count($final['respondents'])>0) { $this->ssi->logComment("Submitting ".count($final['respondents'])." members to SSI."); $submissions=$this->submitBulk($json_final); $this->ssi->logComment("Submitted has ".count($submissions)." errors."); $this->ssi->logComment(json_encode($submissions)); $this->ssi->addFinishComment("Submission errors for.batch=".count($members).".data>>>.".json_encode($submissions)); //return (count($submissions)===0) ? true : false; return count($submissions); } else { $this->ssi->logComment("No members to submit! Could be bad?"); return false; } } } /* ------------------------------------------------------------- */ /* * SSI specific db calls for ssi_member_list and ssi_member_list_prev * @param instance of SSI * @extends CW_db (class.DBConnectionETL.php) */ /* ------------------------------------------------------------- */ class SSI_db extends CW_db { function __construct(SSI $ssi) { $this->ssi=$ssi; ///Init database connections to Slave and ETL $this->init($ssi->getSite(),$ssi->getEnv()); $this->connectToSlave(); $this->ssi->logComment("Connecting to ".$this->ssi->getEnv()." SLAVE >>> ".$this->db_host); $this->connectToEtl(); $this->ssi->logComment("Connecting to ".$this->ssi->getEnv()." ETL >>> ".$this->db_host); } public function checkMemberPartnerIntegration() { $sql = "SELECT COUNT(*) FROM `{$this->etl_db}`.`member_partner_integration`"; $result = mysql_query($sql, $this->etl_con) or die($this->ssi->logComment(mysql_error())); if ( $row = mysql_fetch_array($result, MYSQL_NUM) ) { if ( (int)$row[0] == 0 ) { $this->ssi->logComment( "member_partner_integration table is empty ... exiting!"); $this->ssi->endLog('Finished: '); $this->ssi->sendEmailAlert(" Problem Alert:\n The member_partner_integration table was found empty during the daily SSI partner update.\n\n Update operation was aborted.\n\n EOD;"); return false; } } return true; } public function insertEmailPartner($name,$address_domain,$type) { $sql = "INSERT INTO `{$this->slv_db}`.`email_partner` (partner_name,email_address_domain,partner_type) VALUES ('$name','$address_domain','$type')"; $result = mysql_query($sql, $this->slv_con) or die($this->ssi->logComment(mysql_error())); } public function dropMemberListPrev() { $sql = "DROP TABLE IF EXISTS `{$this->etl_db}`.`ssi_member_list_prev`"; $result = mysql_query($sql, $this->etl_con) or die($this->ssi->logComment(mysql_error())); $this->ssi->logComment("Successfully dropped {$this->etl_db}.ssi_member_list_prev"); return true; } /* BELOW USED FOR TESTING PUPOSES public function copyFromCintPrevToSSIPrev() { $sql = "CREATE TABLE IF NOT EXISTS `{$this->etl_db}`.`ssi_member_list_prev` ( `member_id` INT(11) NOT NULL UNIQUE DEFAULT '0', `member_code` INT(11) NOT NULL DEFAULT '0', PRIMARY KEY (`member_id`)) ENGINE=MyISAM SELECT * FROM `{$this->etl_db}`.`cint_member_list_prev`"; $result = mysql_query($sql, $this->etl_con) or die($this->ssi->logComment(mysql_error())); $this->ssi->logComment("Successfully copied new {$this->etl_db}.ssi_member_list_prev from {$this->etl_db}.cint_member_list_prev"); return true; } */ public function createMemberListPrev() { $sql = "RENAME TABLE `{$this->etl_db}`.`ssi_member_list` TO `{$this->etl_db}`.`ssi_member_list_prev`"; $result = mysql_query($sql, $this->etl_con) or die($this->ssi->logComment(mysql_error())); $this->ssi->logComment("Successfully renamed {$this->etl_db}.ssi_member_list to {$this->etl_db}.ssi_member_list_prev"); return true; } public function populateMemberList() { $sql = "CREATE TABLE IF NOT EXISTS `{$this->etl_db}`.`ssi_member_list` ( `member_id` INT(11) NOT NULL UNIQUE DEFAULT '0', `member_code` INT(11) NOT NULL DEFAULT '0', PRIMARY KEY (`member_id`)) ENGINE=MyISAM SELECT * FROM `{$this->etl_db}`.`member_partner_integration`"; $result = mysql_query($sql, $this->etl_con) or die($this->ssi->logComment(mysql_error())); $this->ssi->logComment("Successfully created new {$this->etl_db}.ssi_member_list from {$this->etl_db}.member_partner_integration"); } private function getMemberListPrevCount() { $sql_prev = "SELECT COUNT(*) FROM `{$this->etl_db}`.`ssi_member_list_prev`"; $result_prev = mysql_query($sql_prev, $this->etl_con) or die($this->ssi->logComment(mysql_error())); $row = mysql_fetch_array($result_prev, MYSQL_NUM); return (int)$row[0]; } private function getMemberListCount() { $sql = "SELECT COUNT(*) FROM `{$this->etl_db}`.`ssi_member_list`"; $result = mysql_query($sql, $this->etl_con) or die($this->ssi->logComment(mysql_error())); $row = mysql_fetch_array($result, MYSQL_NUM); return (int)$row[0]; } public function compareMemberListCounts() { $prev_count = $this->getMemberListPrevCount(); $new_count = $this->getMemberListCount(); if ( $prev_count == $new_count ) { $this->ssi->logComment("ssi_member_list_prev and ssi_member_list appear identical ... exiting!"); $this->ssi->endLog('Finished: '); $this->ssi->sendEmailAlert("Problem Alert:\n\n ssi_member_list_prev and ssi_member_list appear identical during the daily SSI partner update.\n\n Update operation was aborted."); return false; } return true; } // Run this DELETE query for SE only. // This removes any SE member having a duplicate email address with a member in IBD. public function deleteDuplicateSEMembers() { $sql = "DELETE FROM `{$this->etl_db}`.`ssi_member_list` WHERE member_id IN ( SELECT se_ms.member_id FROM `sendearnings`.`member_status` se_ms, `id`.`member_status` id_ms WHERE se_ms.email = id_ms.email )"; $this->ssi->logComment($sql); $result = mysql_query($sql, $this->etl_con) or die($this->ssi->logComment(mysql_error())); $this->ssi->logComment("Successfully removed duplicate emails from SSI_MEMBER_LIST for SE."); } public function getMembersToRemove() { // Which members need to be deleted in SSI's DB? $sql = "SELECT member_id, member_code FROM `{$this->etl_db}`.`ssi_member_list_prev` WHERE member_id NOT IN (SELECT member_id FROM `{$this->etl_db}`.`ssi_member_list`)"; $result = mysql_query($sql, $this->etl_con) or die($this->ssi->logComment(mysql_error())); return $result; } public function getQuestionFromSurveyPartnerXref() { $sql = "SELECT DISTINCT survey_partner_question_desc FROM `{$this->slv_db}`.`survey_partner_xref` WHERE survey_partner_id = {$this->ssi->getPartnerID()} ORDER BY survey_partner_question_desc"; $result = mysql_query($sql, $this->etl_con) or die($this->ssi->logComment(mysql_error())); return $result; } public function getSurveyMembers($features, $only_new=true) { $sql = "SELECT DISTINCT member_code as respondentID, left(trim(ms.zip),5) AS postalcode, (SELECT month(dd.date_key) FROM $this->slv_db.survey_results_dob srdob, $this->slv_db.date_dim dd WHERE dd.julian = srdob.plain_value AND srdob.member_id = sml.member_id) AS monthdob ,(SELECT day(dd.date_key) FROM $this->slv_db.survey_results_dob srdob, $this->slv_db.date_dim dd WHERE dd.julian = srdob.plain_value AND srdob.member_id = sml.member_id) AS daydob ,(SELECT year(dd.date_key) FROM $this->slv_db.survey_results_dob srdob, $this->slv_db.date_dim dd WHERE dd.julian = srdob.plain_value AND srdob.member_id = sml.member_id) AS yeardob "; ///Loop and append select for each feature passed in foreach($features as $feature) { $sql .= ",(SELECT GROUP_CONCAT(DISTINCT survey_partner_answer_id) FROM $this->slv_db.survey_results sr, $this->slv_db.survey_partner_xref spx, $this->slv_db.survey_answers sa WHERE sr.member_id=ms.member_id AND spx.survey_partner_question_desc = '$feature' AND survey_partner_id = {$this->ssi->getPartnerID()} AND sr.survey_question_id=spx.survey_question_id AND sr.survey_answer_id=spx.survey_answer_id) as $feature"; } $sql .=" FROM $this->etl_db.ssi_member_list sml JOIN $this->slv_db.member_status ms ON sml.member_id = ms.member_id "; if($only_new===true) { $sql .=" WHERE sml.member_id NOT IN (SELECT member_id FROM `{$this->etl_db}`.`ssi_member_list_prev`)"; } ///For debugging //$sql.=" limit 20"; ////$this->ssi->logComment($sql); $result = mysql_query($sql, $this->etl_con) or die($this->ssi->logComment(mysql_error())); return $result; } public function getMemberFeatures($id) { $sql = "SELECT DISTINCT sa.answer,survey_partner_question_desc, survey_partner_answer_id,survey_partner_answer_desc FROM $this->slv_db.survey_results sr, $this->slv_db.survey_partner_xref spx, $this->slv_db.survey_answers sa WHERE sr.member_id=$id AND survey_partner_id = {$this->ssi->getPartnerID()} AND sr.survey_question_id=spx.survey_question_id AND sr.survey_answer_id=spx.survey_answer_id AND sr.survey_answer_id=sa.id ORDER BY survey_partner_question_desc"; $result = mysql_query($sql, $this->etl_con) or die($this->ssi->logComment(mysql_error())); return $result; } }

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)
8.3.60.0110.01117.13
8.3.50.0130.00522.12
8.3.40.0110.00419.09
8.3.30.0040.01119.35
8.3.20.0040.00420.54
8.3.10.0000.00821.82
8.3.00.0000.00819.11
8.2.180.0040.01218.54
8.2.170.0090.01222.96
8.2.160.0110.00422.20
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0080.00026.16
8.2.120.0030.00519.66
8.2.110.0030.00622.27
8.2.100.0090.00317.97
8.2.90.0000.00819.34
8.2.80.0030.00617.97
8.2.70.0080.00017.88
8.2.60.0000.01018.05
8.2.50.0030.00618.07
8.2.40.0030.00618.40
8.2.30.0000.00719.68
8.2.20.0040.00417.90
8.2.10.0030.00518.11
8.2.00.0060.00317.91
8.1.280.0140.00725.92
8.1.270.0000.01119.15
8.1.260.0060.00326.35
8.1.250.0030.00628.09
8.1.240.0070.00423.96
8.1.230.0040.00819.28
8.1.220.0030.00517.79
8.1.210.0040.00418.77
8.1.200.0030.00717.35
8.1.190.0040.00417.25
8.1.180.0040.00418.10
8.1.170.0060.00318.71
8.1.160.0080.00022.20
8.1.150.0030.00519.00
8.1.140.0000.00817.57
8.1.130.0040.00417.91
8.1.120.0060.00317.57
8.1.110.0030.00617.57
8.1.100.0040.00417.55
8.1.90.0080.00017.55
8.1.80.0040.00417.46
8.1.70.0000.00717.42
8.1.60.0060.00317.76
8.1.50.0100.00317.61
8.1.40.0000.00917.66
8.1.30.0030.00617.67
8.1.20.0030.00617.85
8.1.10.0040.00417.60
8.1.00.0000.00817.65
8.0.300.0080.00018.77
8.0.290.0040.00417.13
8.0.280.0030.00518.69
8.0.270.0000.00717.43
8.0.260.0040.00417.38
8.0.250.0070.00017.29
8.0.240.0040.00417.27
8.0.230.0070.00017.30
8.0.220.0070.00017.05
8.0.210.0000.00717.20
8.0.200.0050.00217.25
8.0.190.0000.00817.19
8.0.180.0040.00417.12
8.0.170.0060.00317.13
8.0.160.0000.00717.23
8.0.150.0030.00617.19
8.0.140.0030.00617.20
8.0.130.0000.00613.68
8.0.120.0030.00617.21
8.0.110.0000.00817.21
8.0.100.0030.00617.19
8.0.90.0040.00417.07
8.0.80.0070.01117.25
8.0.70.0080.00017.01
8.0.60.0030.00517.15
8.0.50.0050.00317.02
8.0.30.0140.01217.27
8.0.20.0080.01317.40
8.0.10.0030.00617.07
8.0.00.0090.00916.91
7.4.330.0050.00015.21
7.4.320.0030.00316.77
7.4.300.0000.00716.82
7.4.290.0040.00416.67
7.4.280.0060.00316.76
7.4.270.0040.00416.65
7.4.260.0080.00316.75
7.4.250.0040.00416.58
7.4.240.0060.00116.79
7.4.230.0000.00716.67
7.4.220.0090.00916.75
7.4.210.0020.01416.75
7.4.200.0050.00216.62
7.4.160.0100.01016.98
7.4.150.0080.01417.40
7.4.140.0090.01117.86
7.4.130.0120.00716.72
7.4.120.0080.01016.72
7.4.110.0060.01216.78
7.4.100.0090.00916.82
7.4.90.0120.00616.63
7.4.80.0070.01519.39
7.4.70.0090.00916.66
7.4.60.0110.00616.82
7.4.50.0040.00416.41
7.4.40.0060.01016.53
7.4.30.0060.01216.69
7.4.00.0030.01414.89
7.3.330.0040.00413.47
7.3.320.0030.00313.30
7.3.310.0030.00616.51
7.3.300.0030.00516.47
7.3.290.0070.00016.35
7.3.280.0050.01316.51
7.3.270.0060.01217.40
7.3.260.0090.00816.64
7.3.250.0060.01616.64
7.3.240.0110.00816.53
7.3.230.0090.01816.55
7.3.210.0140.00316.49
7.3.200.0150.00619.39
7.3.190.0110.00516.59
7.3.180.0060.01016.54
7.3.170.0120.01216.55
7.3.160.0110.00616.50
7.2.330.0080.01416.74
7.2.320.0120.00616.70
7.2.310.0040.01416.55
7.2.300.0100.00716.78
7.2.290.0090.00916.79
7.2.60.0060.00616.81
7.2.00.0000.01119.00
7.1.200.0090.00615.64
7.1.100.0000.01117.80
7.1.70.0000.00817.08
7.1.60.0060.01819.46
7.1.50.0130.01316.53
7.1.00.0070.08722.41
7.0.200.0030.00516.62
7.0.140.0000.08022.00
7.0.90.0600.08020.00
7.0.80.0570.08320.04
7.0.70.0430.06020.30
7.0.60.0570.06720.11
7.0.50.0530.05720.48
7.0.40.0130.07720.04
7.0.30.0130.04720.09
7.0.20.0030.08719.96
7.0.10.0070.08320.03
7.0.00.0030.08020.08
5.6.280.0030.06720.94
5.6.240.0170.07320.63
5.6.230.0170.07720.76
5.6.220.0030.08020.73
5.6.210.0100.07020.59
5.6.200.0100.08021.08
5.6.190.0100.05321.07
5.6.180.0070.08321.05
5.6.170.0100.07021.08
5.6.160.0070.08321.29
5.6.150.0030.08721.05
5.6.140.0000.09021.22
5.6.130.0070.08321.06
5.6.120.0230.07321.20
5.6.110.0170.06021.22
5.6.100.0070.08321.05
5.6.90.0200.08021.18
5.6.80.0030.08720.62
5.6.70.0070.04720.43
5.6.60.0070.07720.43
5.6.50.0130.07020.67
5.6.40.0130.07020.55
5.6.30.0130.07720.51
5.6.20.0200.07020.49
5.6.10.0130.07020.61
5.6.00.0070.05020.42
5.5.380.0130.07720.66
5.5.370.0000.08720.46
5.5.360.0070.08720.46
5.5.350.0130.08020.46
5.5.340.0030.08720.98
5.5.330.0170.06721.05
5.5.320.0070.06321.04
5.5.310.0070.05720.86
5.5.300.0100.08720.90
5.5.290.0230.06720.91
5.5.280.0030.08020.95
5.5.270.0070.08321.04
5.5.260.0130.04721.00
5.5.250.0100.07320.72
5.5.240.0130.07020.28
5.5.230.0100.07320.32
5.5.220.0030.08020.32
5.5.210.0070.08020.30
5.5.200.0070.07320.33
5.5.190.0070.08320.30
5.5.180.0130.07720.36
5.5.160.0100.07020.29
5.5.150.0100.05320.25
5.5.140.0170.07020.20
5.5.130.0100.07720.33
5.5.120.0100.05320.34
5.5.110.0100.08020.25
5.5.100.0170.07020.18
5.5.90.0030.05720.24
5.5.80.0130.07020.13
5.5.70.0070.06320.22
5.5.60.0000.07720.25
5.5.50.0030.04320.17
5.5.40.0100.07020.27
5.5.30.0070.08020.26
5.5.20.0130.07320.08
5.5.10.0000.09020.24
5.5.00.0100.08020.16
5.4.450.0100.08319.43
5.4.440.0100.07319.27
5.4.430.0130.04719.46
5.4.420.0130.07019.41
5.4.410.0100.03319.29
5.4.400.0070.07718.91
5.4.390.0030.04719.27
5.4.380.0070.07719.07
5.4.370.0070.07319.06
5.4.360.0000.08019.08
5.4.350.0130.07319.08
5.4.340.0130.07019.16
5.4.320.0130.06319.24
5.4.310.0070.06319.25
5.4.300.0100.07719.09
5.4.290.0100.06719.16
5.4.280.0170.03319.09
5.4.270.0130.07319.16
5.4.260.0100.06019.08
5.4.250.0070.06319.23
5.4.240.0100.06018.94
5.4.230.0100.07019.00
5.4.220.0030.06319.26
5.4.210.0100.06019.23
5.4.200.0100.07319.13
5.4.190.0130.04019.25
5.4.180.0070.05019.25
5.4.170.0070.07719.07
5.4.160.0070.07318.93
5.4.150.0070.04019.15
5.4.140.0130.07016.45
5.4.130.0070.07016.40
5.4.120.0100.06716.24
5.4.110.0030.07716.38
5.4.100.0130.07016.55
5.4.90.0100.03716.41
5.4.80.0030.07716.53
5.4.70.0130.06716.43
5.4.60.0000.05716.54
5.4.50.0030.06016.48
5.4.40.0100.05716.35
5.4.30.0100.06716.54
5.4.20.0070.05316.49
5.4.10.0000.07716.39
5.4.00.0070.06315.84

preferences:
60.85 ms | 401 KiB | 5 Q