When making an ajax request from javascript to my server, always after 60 seconds it returns http 503 code. The other strange thing is that the script on the server finishes satisfactorily because later I check and do everything I had to do, but upon receiving 503 I can not show the correct result to the client.
On my server I use Apache, php, php-fpm.
The script takes longer because it makes a request to an api from a third party and sends two emails. In addition, it makes several requests and writes in database.
I added the following line to the script and I still have the problem
set_time_limit(180);
Note: the script works well on the test server but not on the production server.
Update
The portion of the php code that is executed is the following:
$productos = $cart->getProducts();
$this->data['CodigoCompra'] = $cart->id;
$this->data['FechaCompra'] = date('Y-m-d H:i:s');
$this->data['FechaEntrega'] = date('Y-m-d H:i:s');
$this->data['MontoTotal'] = $cart->getOrderTotal();
$this->data['productos'] = array();
foreach ($productos as $producto) {
$p = array(
"TipoCodigoProducto" => "SKU",
"CodigoProducto" => $producto['reference'],
"NombreProducto" => $producto['name'],
"CantidadProducto" => $producto['cart_quantity'],
"PrecioUnitario" => $producto['price'],
"Informacion" => "",
);
array_push($this->data['productos'], $p);
}
if (empty($this->data['productos'])) {
$oc->estado = MercadoPublicoOC::$ESTADOS[2];
$oc->save(true);
$this->ajaxDie(Tools::jsonEncode(array("error" => array("Sin productos asociados. Por favor verifique su carrito de compras"))));
}
$address = new Address((int)$cart->id_address_delivery);
if (!$usuario_mp->findRut($address->rut_cliente)) {
$oc->estado = MercadoPublicoOC::$ESTADOS[2];
$oc->save(true);
$this->ajaxDie(Tools::jsonEncode(array("error" => array("Rut no encontrado"))));
}
$state = new State($address->id_state);
$this->data['RutComprador'] = $usuario_mp->Rut;
$this->data['CodigoUsuario'] = $usuario_mp->Codigo;
$this->data['CodigoUsuarioTienda'] = $cart->id_customer;
$this->data['DireccionDespacho'] = $address->address1 . '. ' . $address->comuna . '. ' . $state->name . '.';
set_time_limit(180);
$resultado = $this->CallAPI('POST', 'https://me-reservo-la-direccion/RegistroDeCompraQA/Registrar', $this->data);
if ($resultado['info']['http_code'] != 200) {
$logger->logError('Respuesta HTTP de API de Mercado Publico invalido: ' . $resultado['info']['http_code']);
$oc->estado = MercadoPublicoOC::$ESTADOS[2];
$oc->save(true);
$this->ajaxDie(Tools::jsonEncode(array("error" => array("Error generando Orden de Compra. Por favor, verifique en Mercado Público o intente más tarde."))));
}
$resultado2 = Tools::jsonDecode($resultado['response'], true);
if ($resultado2 == null) {
$logger->logError('Resultado de API de Mercado Publico invalido: ' . $resultado['response']);
$oc->estado = MercadoPublicoOC::$ESTADOS[2];
$oc->save(true);
$this->ajaxDie(Tools::jsonEncode(array("error" => array("Error generando Orden de Compra. Por favor, verifique en Mercado Público o intente más tarde."))));
}
$oc->id_cart = $cart->id;
$oc->estado = MercadoPublicoOC::$ESTADOS[1];
$oc->FechaRespuesta = $resultado2['FechaRespuesta'];
$oc->Respuesta = $resultado2['Respuesta'];
$oc->CodigoRespuesta = $resultado2['CodigoRespuesta'];
$oc->Url = $resultado2['Url'];
$oc->save(true);
if ($resultado2['CodigoRespuesta'] != 1) {
$logger->logError('Codigo de respuesta no satisfactorio: ' . $resultado['response']);
$oc->estado = MercadoPublicoOC::$ESTADOS[2];
$oc->save(true);
$this->ajaxDie(Tools::jsonEncode(array("error" => array("Error generando Orden de Compra.".PHP_EOL.$resultado2["Respuesta"].PHP_EOL."Por favor, verifique en Mercado Público o intente más tarde."))));
}
$customer = new Customer($cart->id_customer);
if (!Validate::isLoadedObject($customer))
$this->redireccionar((new Link)->getPageLink('order&step=1'));
$currency = Context::getContext()->currency;
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
$this->module->validateOrder((int)$cart->id, Configuration::get('PS_OS_OUTOFSTOCK_UNPAID'), $total, $this->module->displayName, NULL, NULL, (int)$currency->id, false, $customer->secure_key);
$this->redireccionar((new Link)->getPageLink('order-confirmation&id_cart='.(int)$cart->id.'&id_module='.(int)$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key));
Use prestashop