@Sazanovdm

Почему возникает ошибка в этом коде?

Когда я отправляю 1-2-3 ну может 5 POST запросов для запуска этого скрипта, то все работает нормально, но стоит лишь отправить 10+ POST запросов тем самым запустим 10 таких сценариев одновременно, то получаю ошибку:
Error! Reading image data from stdin is not available this tesseract version
Required version is 3.03-rc1, actual version is fault

Generated command:
"tesseract" "" "/tmp/ocrEKUVOy"
Error! The command did not produce any output.

====
Returned message:
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted (core dumped)
Error! The command did not produce any output.

Сам код:
set_time_limit(0);
include_once("include/functions.php");
include_once("include/db_functions.php");
include_once("simple_html_dom/simple_html_dom.php");
include_once("vendor/autoload.php");

class myClass
{
    private $function;
    private $DB;
    private $html;
    private $Imagick;
    private $tesseract;

    public function __construct()
    {
        $this->function = new Functions();
        $this->DB = new DB();
        $this->html = new simple_html_dom();
        $this->Imagick = new Imagick();
        $this->tesseract = new thiagoalessio\TesseractOCR\TesseractOCR();
    }

    public function GetImage($cookie)
    {
        $ch = curl_init($url);
        curl_setopt_array($ch, array(
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_TIMEOUT        => 60,
            CURLOPT_CONNECTTIMEOUT => 35,
            CURLOPT_COOKIEFILE     => $cookie,
            CURLOPT_COOKIEJAR      => $cookie,
            CURLOPT_ENCODING       => 'gzip, deflate'
        ));

        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Connection: keep-alive',
            'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36',
            'Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7'
        ));

        $result = curl_exec($ch);
        $info = curl_getinfo($ch);
        curl_close($ch);

        if ($info["http_code"] == 200)
        {
            $this->Imagick->readImageBlob($result);
            $this->Imagick->resizeImage(450,120,Imagick::FILTER_CATROM,1);
            $this->Imagick->extentImage(450,120,Imagick::FILTER_CATROM,1);
            // some other options imagick..
            $data = $this->Imagick->getImageBlob();
            $size = $this->Imagick->getImageLength();
            // read image
            $this->tesseract->imageData($data, $size)->lang('eng');
            $code = $this->tesseract->run();
            $this->tesseract->clearCache();                

            if ($code)
            {
                if ($this->Validate($code, $cookie))
                {
                    return $code;
                }
            }

            return $this->GetImage($cookie);
        }
    }

    public function Start($id)
    {
    	$this->GetImage($cookie);
    }
}

if (isset($_POST["order"]) && !empty($_POST["order"]))
{
    $id = $_POST["order"];
    $object = new myClass();
	$object->Start($id);
}


Вопрос: Возможно гуру PHP увидят тут ошибки? Почитав в интернете я пришел к выводу, что не хватает памяти, но при этом, изучив графики в аккаунте digitalocean, не вижу пиковых нагрузок, или не там смотрю?
Графики
5fb28dcc8de37894345402.png


memory_limit = 128 на данный момент. Пробовал ставить 256, и повторял отправку 10-ти запросов, ничего не изменилось.
  • Вопрос задан
  • 199 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы