Скрипт сбой apache сервера [альтернативы] - PullRequest
0 голосов
/ 10 октября 2019

Можете ли вы дать мне альтернативу этому сценарию?

При запуске на странице происходит сбой сервера apache. Я не знаю, является ли это ошибкой сценария или самим сервером.

Я работаю с PHP 7.2.23 с FPM / FastCGI.

Это простой сценарий, который ищет толькостоимость различных товаров и печатных изданий на сайте.

script.js

function getValue(val) {
    return new Promise((res, rej) => {
        const xhr = new XMLHttpRequest();
        xhr.open('GET', 'search.php?id=' + val + '&periodicidade=monthly');
        xhr.onload = function() {
        if (xhr.status === 200) res(xhr.responseText);
        else rej(xhr.status);
        };
        xhr.send();
    });
}
const valores = [171, 162, 165, 176, 174, 175, 170, 164, 160, 168, 161, 167, 159 ];
Promise.all(valores.map(getValue))
    .then(planos => {
        document.getElementById("serverList1").textContent=planos[0].replace(".", ",").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.");
        document.getElementById("serverList2").textContent=planos[1].replace(".", ",").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.");
        document.getElementById("serverList3").textContent=planos[2].replace(".", ",").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.");
        document.getElementById("serverList4").textContent=planos[3].replace(".", ",").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.");
        document.getElementById("serverList5").textContent=planos[4].replace(".", ",").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.");
        document.getElementById("serverList6").textContent=planos[5].replace(".", ",").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.");
        document.getElementById("serverList7").textContent=planos[6].replace(".", ",").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.");
        document.getElementById("serverList8").textContent=planos[7].replace(".", ",").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.");
        document.getElementById("serverList9").textContent=planos[8].replace(".", ",").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.");
        document.getElementById("serverList10").textContent=planos[9].replace(".", ",").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.");
        document.getElementById("serverList11").textContent=planos[10].replace(".", ",").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.");
        document.getElementById("serverList12").textContent=planos[11].replace(".", ",").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.");
        document.getElementById("serverList13").textContent=planos[12].replace(".", ",").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.");
        console.log(planos);
    })
.catch(err => console.log(err));

search.php

$id_plano=$_GET['id'];
$periodicidade=$_GET['periodicidade'];

$retornar_valor=processaValor("https://sub.domain.com.br/feeds/productsinfo.php?pid=".$id_plano."&get=price&billingcycle=".$periodicidade."");
echo $retornar_valor;

function processaValor($url) {
    if (!function_exists('curl_init')){ 
        die('CURL is not installed!');
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    $aspas = strpos($output, "'");
    $valor = substr($output, $aspas+1, -3);
    curl_close($ch);
    return str_replace(['.', ','], ['', '.'], $valor);
}

ОБНОВЛЕНИЕ: Я вижу, что эта проблема возникает, когда слишком много запросов в script.js, как тот, который я показал.

Если я размещаю только 3 запроса, это работает, еслиЯ оставляю все те, кто там, висит.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...