3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * DIRECCION EJECUTIVA DE INGRESOS * GENERADOR DE URL CORTA, DEI-MOVIL * 2014 */ class Api{ // Variable MySQL para manipular BD con la clase DataBase. private $mysql = NULL; // Variable para manipular Response en JSON. private $json_responses = NULL; // Variable para utilizar otras funciones de la clase utilidades. private $utils = NULL; // Variable para manipular clase para enviar el correo. private $emailServer = NULL; // Variable para validar RTN (class). private $RTN = NULL; // Variables para inicializar BD. private $dbuser; private $dbpassword; private $dbhost; private $dbname; // Data form private $post_data; // Final response public $api_response = ""; // Variable para verificar validez de parámetros. private $response_validate = ""; // Variable Link servicio URL private $url_host; // Variable Tamaño token de URL Corto private $tam_token; // Variable Link Formularios PreImpresos DEI private $url_formularios; // Variable cantidad dias, validez URL private $validez_url; // Variable controlar el numero de peticiones en un link private $num_peticiones; // Variable que contiene los formularios estaticos. private $formularios_estaticos; // Variable que contiene valor TOKEN generado para el link. private $token; // Variable para almacenar la respuesta final (JSON). private $response = ""; // Variable para almacenar el LINK o QUERY STRING del formulario generado. private $http_query = ""; // Initialize api public function __construct($datosDB, $request, $post_data_object, $formularios_estaticos = "", $url_host = "", $tam_token = "", $url_formularios = "", $validez_url = "", $num_peticiones = ""){ $this->dbhost = $datosDB["host"]; $this->dbname = $datosDB["db"]; $this->dbpassword = $datosDB["pass"]; $this->dbuser = $datosDB["user"]; $this->url_host = $url_host; $this->tam_token = $tam_token; $this->url_formularios = $url_formularios; $this->validez_url = $validez_url; $this->num_peticiones = $num_peticiones; $this->formularios_estaticos = $formularios_estaticos; $this->post_data = $post_data_object; // Inicializamos JSON response $this->json_response_init(); // Inicializamos conexión MySQL $this->mysql_init(); // Inicializamos las utilidades $this->utils_init(); // Inicializamos el servidor SMTP $this->smtp_init(); // Iniciamos el validar de RTN $this->RTN_init(); if(in_array($request, array("generar", "url"))){ $this->api_response = $this->{"request_".$request}(); }else{ if($request == NULL || $request == ""){ $this->json_responses->makeError("ApiRequestException", "Se requiere un metodo para consumir el web service."); }else{ $this->json_responses->makeError("ApiRequestException", $request . " no existe en el web service."); } $this->api_response = $this->json_responses->getStringResponseOut(); } } private function mysql_init(){ $this->mysql = new Database($this->dbhost, $this->dbuser, $this->dbpassword, $this->dbname); } private function json_response_init(){ $this->json_responses = new JSONResponse(); } private function utils_init(){ $this->utils = new Utilidades(); } private function smtp_init(){ $this->emailServer = new enviarEmail(SMTP_SERVER, SMTP_SERVER_PORT, SMTP_USER, SMTP_PASSWORD, FROM_NAME); } private function RTN_init(){ $this->RTN = new RTN(RTN_SERVIDOR, RTN_METODO_WS, RTN_PARAMETRO); } /** * GENERAR URL */ private function request_generar(){ $this->verificarSiFormularioEstatico($this->post_data->form); // Verificamos que sea un formulario estatico o no-generado en el sistema. if(isset($this->post_data->form)){ if(empty($this->post_data->form)){ $this->json_responses->makeError("FormValidateException", "Se requiere de un codigo de formulario."); } }else{ $this->json_responses->makeError("FormValidateException", "No se recibio el codigo del formulario."); } if(isset($this->post_data->rtn)){ if(empty($this->post_data->rtn)){ $this->json_responses->makeError("FormValidateException", "Se requiere de un numero RTN valido."); }elseif(strlen($this->post_data->rtn) < TAM_RTN){ $this->json_responses->makeError("FormValidateException", "El RTN ingresado no es valido. Debe contener 14 digitos."); }elseif(!$this->RTN->validar($this->post_data->rtn)){ // Validamos RTN en la DEI. $this->json_responses->makeError("RTNValidateException", "El RTN ingresado no EXISTE. Ingrese uno valido o existente."); } }else{ $this->json_responses->makeError("FormValidateException", "No se recibio el numero RTN."); } if(isset($this->post_data->correo)){ if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $this->post_data->correo)){ $this->json_responses->makeError("FormValidateException", "El correo ".$this->post_data->correo." no es valido."); } }else{ $this->json_responses->makeError("FormValidateException", "El correo no fue recibido."); } $this->response_validate = $this->json_responses->getStringResponseOut(); if(!empty($this->response_validate)){ return $this->response_validate; }else{ $this->response_validate = ""; } $this->BuildRequestGenerar(); // Generamos el resultado. return $this->json_responses->getStringResponseOut(); } private function BuildRequestGenerar(){ if($this->json_responses->getStringResponseOut() == "" || $this->json_responses->getStringResponseOut() == NULL){ $this->generarParametros(); $this->BuildRequestGenerarInsertarLink(); $this->BuildRequestGenerarInsertarDatosGenerados(); $this->BuildRequestGenerarResultados(); $this->json_responses->makeResponse($this->response); } } private function BuildRequestGenerarInsertarLink(){ $this->token = substr(md5(time()."apiKeyToken"),0,$this->tam_token); $datos_link = array( "id" => $this->token, "link" => $this->http_query, "session_vida" => time(), "peticiones" => $this->num_peticiones, "correo" => $this->post_data->correo, ); $this->mysql->insert("Links", $datos_link); } private function BuildRequestGenerarInsertarDatosGenerados(){ $datos_generados = array( "tipo_formulario" => $this->post_data->form, "ip" => ip2long($this->utils->obtenerIP()), // ip2long, convertimos a int long unsigned la ip, y la guardamos con entero en la BD. "id_dispositivo" => $this->post_data->dispositivo, "nombre_contribuyente" => $this->post_data->nombre, "nombre_contribuyente_ext" => $this->post_data->nombre2, "rtn" => $this->post_data->rtn, "correo" => $this->post_data->correo ); $this->mysql->insert("Generados", $datos_generados); } private function BuildRequestGenerarResultados(){ $this->response = new StdClass(); $this->response->mensaje = "OK"; $this->response->url = $this->url_host . $this->token; if($this->emailServer->enviarLink($this->post_data->correo, $this->url_host . $this->token)){ $this->response->correo = "Fue enviado."; }else{ $this->response->correo = "No fue enviado."; } } /** * TRAE DATOS DEL LINK */ private function request_url(){ if(isset($this->post_data->id)){ if(empty($this->post_data->id)){ $this->json_responses->makeError("UrlParamException", "Se requiere de un parametro para continuar."); } }else{ $this->json_responses->makeError("UrlParamException", "No se recibio el parametro."); } $this->response_validate = $this->json_responses->getStringResponseOut(); if(!empty( $this->response_validate)){ return $this->response_validate; }else{ $this->response_validate = ""; } if($this->json_responses->getStringResponseOut() == "" || $this->json_responses->getStringResponseOut() == NULL){ $token = $this->mysql->getResults("SELECT link, session_vida, peticiones, correo FROM `Links` WHERE id = '".$this->mysql->_real_escape($this->post_data->id)."'"); if(!is_null($token) && !empty($token[0])){ if((time() - $token[0]->session_vida) <= $this->utils->HoraVencimiento($this->validez_url)){ // Verificamos que el enlace no tenga mas tiempo vivo. if($this->utils->verificarPeticiones($token[0]->peticiones) != "UrlRequestExceeded"){ $response = new StdClass(); $response->mensaje = "OK"; if($this->utils->verificarTipoLinkGenerado($token[0]->link)){ // Aqui verificamos si es QUERY STRING O un LINK EXTERNO O ENTERO CON IGUAL O DIFERENTE DOMINIO DE LA DEI. $response->url = $token[0]->link; }else{ $response->url = $this->url_formularios . $token[0]->link; } $this->modificarPeticionesLink(($token[0]->peticiones-1), $this->post_data->id); $this->json_responses->makeResponse($response); }else{ $this->json_responses->makeError("UrlRequestExceededException", "Ya ha superado el limite de peticiones/descargas a este formulario."); } }else{ $this->json_responses->makeError("UrlTimeException", "El tiempo de vigencia del Formulario ha expirado."); } }else{ $this->json_responses->makeError("UrlRequestException", "La URL no existe o ha expirado."); } } return $this->json_responses->getStringResponseOut(); } /** * OTROS METODOS */ private function generarParametros(){ $datos = array( "nombre" => $this->post_data->nombre, "mxw_nombre_charsleft" => $this->post_data->mxw_nombre_charsleft, "nombre2" => $this->post_data->nombre2, "mxw_nombre2_charsleft" => $this->post_data->mxw_nombre2_charsleft, "rtn" => $this->post_data->rtn, "form" => $this->post_data->form, "ip" => $this->utils->obtenerIP(), "fecha" => date("d/m/Y"), "KT_Custom1" => "Generar+Formulario", "KT_Custom1" => "Generar+Formulario" ); $this->http_query = http_build_query($datos); } private function modificarPeticionesLink($peticion, $id_url){ $datos = array("peticiones" => $peticion); $this->mysql->update('Links', $datos, array("id" => $id_url)); //Para actualizar peticiones al entrar al link. --i; } private function verificarSiFormularioEstatico($formulario){ if(array_key_exists($formulario, $this->formularios_estaticos)){ if(isset($this->post_data->rtn)){ if(empty($this->post_data->rtn)){ $this->json_responses->makeError("FormValidateException", "Se requiere de un numero RTN valido."); }elseif(strlen($this->post_data->rtn) < TAM_RTN){ $this->json_responses->makeError("FormValidateException", "El RTN ingresado no es valido. Debe contener 14 digitos."); }elseif(!$this->RTN->validar($this->post_data->rtn)){ // Validamos RTN en la DEI. $this->json_responses->makeError("RTNValidateException", "El RTN ingresado no EXISTE. Ingrese uno valido o existente."); } }else{ $this->json_responses->makeError("FormValidateException", "No se recibio el numero RTN."); } if(isset($this->post_data->correo)){ if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $this->post_data->correo)){ $this->json_responses->makeError("FormValidateException", "El correo ".$this->post_data->correo." no es valido."); } }else{ $this->json_responses->makeError("FormValidateException", "El correo no fue recibido."); } $this->response_validate = $this->json_responses->getStringResponseOut(); if(!empty($this->response_validate)){ return $this->response_validate; }else{ $this->response_validate = ""; } $this->http_query = $this->formularios_estaticos[$formulario]; $this->BuildRequestGenerarInsertarLink(); $this->BuildRequestGenerarInsertarDatosGenerados(); $this->BuildRequestGenerarResultados(); $this->json_responses->makeResponse($this->response); } } } ?>

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.2.60.0060.00616.21
7.2.00.0060.00619.00
7.1.200.0030.01015.55
7.1.100.0070.00718.16
7.1.70.0060.00916.98
7.1.60.0090.01519.40
7.1.50.0120.01216.54
7.1.00.0000.08322.51
7.0.200.0410.00914.68
7.0.140.0000.07722.05
7.0.80.0000.08320.19
7.0.70.0100.07320.09
7.0.60.0070.07020.05
7.0.50.0070.08020.55
7.0.40.0100.04720.00
7.0.30.0200.07720.09
7.0.20.0100.06720.04
7.0.10.0030.06020.08
7.0.00.0130.04720.18
5.6.280.0000.07321.17
5.6.230.0100.06020.64
5.6.220.0100.07720.61
5.6.210.0130.06720.68
5.6.200.0070.05721.23
5.6.190.0100.07721.17
5.6.180.0000.07021.11
5.6.170.0070.06321.03
5.6.160.0070.08321.10
5.6.150.0030.06721.11
5.6.140.0130.04721.15
5.6.130.0100.04321.20
5.6.120.0100.05021.26
5.6.110.0100.08321.05
5.6.100.0070.06321.18
5.6.90.0000.08021.04
5.6.80.0030.05320.41
5.6.70.0230.06720.59
5.6.60.0070.08720.52
5.6.50.0070.08020.44
5.6.40.0030.08020.46
5.6.30.0200.07320.46
5.6.20.0030.08020.51
5.6.10.0070.05320.53
5.6.00.0070.04320.55
5.5.370.0070.05020.52
5.5.360.0000.06320.46
5.5.350.0170.07020.55
5.5.340.0070.05720.93
5.5.330.0070.08320.96
5.5.320.0030.08020.96
5.5.310.0030.09020.95
5.5.300.0030.04020.86
5.5.290.0070.04720.96
5.5.280.0000.08720.72
5.5.270.0100.07320.91
5.5.260.0130.07720.88
5.5.250.0130.07020.79
5.5.240.0070.05020.28
5.5.230.0100.06720.36
5.5.220.0000.06020.27
5.5.210.0130.07320.27
5.5.200.0030.06020.27
5.5.190.0000.07020.38
5.5.180.0000.09020.21
5.5.160.0170.06720.27
5.5.150.0130.07320.29
5.5.140.0130.06720.27
5.5.130.0070.04320.32
5.5.120.0100.07320.32
5.5.110.0070.05720.30
5.5.100.0070.05020.20
5.5.90.0100.07020.19
5.5.80.0070.05320.19
5.5.70.0070.03720.18
5.5.60.0030.05720.25
5.5.50.0130.06720.09
5.5.40.0100.03320.15
5.5.30.0000.04320.02
5.5.20.0030.04020.17
5.5.10.0100.03320.16
5.5.00.0000.04320.06
5.4.450.0070.08319.54
5.4.440.0070.05719.51
5.4.430.0030.08319.39
5.4.420.0070.08019.38
5.4.410.0100.07319.34
5.4.400.0100.07719.05
5.4.390.0030.08019.14
5.4.380.0030.05319.14
5.4.370.0030.04318.98
5.4.360.0030.08319.14
5.4.350.0100.04718.98
5.4.340.0100.08019.16
5.4.320.0100.05318.88
5.4.310.0100.07719.06
5.4.300.0070.08019.24
5.4.290.0030.05318.97
5.4.280.0170.06319.24
5.4.270.0000.08319.13
5.4.260.0000.07718.97
5.4.250.0070.05719.07
5.4.240.0000.06319.07
5.4.230.0030.04019.22
5.4.220.0030.04018.86
5.4.210.0030.07719.16
5.4.200.0000.04319.15
5.4.190.0070.04319.12
5.4.180.0000.04319.14
5.4.170.0100.04019.04
5.4.160.0030.04018.94
5.4.150.0030.03718.96
5.4.140.0030.03316.42
5.4.130.0000.04016.48
5.4.120.0000.03316.56
5.4.110.0070.05016.35
5.4.100.0070.02716.57
5.4.90.0070.03716.56
5.4.80.0030.03316.48
5.4.70.0030.03716.55
5.4.60.0000.03716.46
5.4.50.0030.03716.39
5.4.40.0000.04016.46
5.4.30.0100.03316.51
5.4.20.0030.03016.51
5.4.10.0070.04316.32
5.4.00.0000.04715.71

preferences:
32.76 ms | 401 KiB | 5 Q