Skip to content

tried to allocate #1578

Description

@demortx

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /var/www/web.ru/system/Config/BaseService.php on line 111

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /var/www/web.ru/system/Debug/Exceptions.php on line 195

OR

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 262144 bytes) in /var/www/web.ru/application/Config/Services.php on line 224

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 262144 bytes) in Unknown on line 0

The problem appears when the cURL or file_get_contents () method is called in the function, I think it is related to the toolbar when it tries to collect all the data from the variables for the report, and somewhere there is a memory leak. for example, parsing the site is not realistic, it appeared just a couple of months ago, before that, everything was ok, I’ll attach sample code


`<?php namespace App\Controllers;

use CodeIgniter\Controller;

class Update extends Controller {

/* @var \Config\Database $db */
public $db;


public $l2oops_url = array(
    'https://l2oops.com/',
    'https://l2oops.com/chronicle/lineage-2-interlude',
    'https://l2oops.com/chronicle/lineage-2-interlude-s-dopolneniyami',
    'https://l2oops.com/chronicle/lineage-2-high-five',
    'https://l2oops.com/chronicle/lineage-2-gracia-epilogue',
    'https://l2oops.com/chronicle/lineage-2-classic',
    'https://l2oops.com/chronicle/lineage-2-goddess-of-destruction',
    'https://l2oops.com/chronicle/lineage-2-gracia-final',
    'https://l2oops.com/chronicle/lineage-2-goddess-of-destruction-lindvior',
    'https://l2oops.com/chronicle/lineage-2-freya',
    'https://l2oops.com/chronicle/lineage-2-ertheia',
    'https://l2oops.com/chronicle/lineage-2-chronicle-c4',
    'https://l2oops.com/chronicle/lineage-2-infinite-odyssey',
    'https://l2oops.com/chronicle/lineage-2-helios',
    'https://l2oops.com/rates/lineage-2-GVE',
    'https://l2oops.com/rates/lineage-2-RVR',

);

public $temp_base_server_list = array();


public function index()
{


    $this->db = \Config\Database::connect();
    $n = new \Simple_html_dom();
    unset($n);


    if(is_array($this->l2oops_url)) {
        foreach ($this->l2oops_url as $url) {


            $html = file_get_html($url); // - Simple_html_dom

            $ul_server = $html->find('ul.server');
            unset($html);
            foreach ($ul_server as $article) {
                $item = null;



                $item['name'] =  @$article->find('li.server_name', 0)->plaintext;
                if(empty($item['name']))
                    continue;


                if(strripos($item['name'], "PTS") OR strripos($item['name'], "pts"))
                    $pts = "[PTS] ";
                else
                    $pts = "";

                $item['name'] = @trim(str_replace(array("pts", "[pts]"), "" , $item['name']));

                $url_site = mb_strtolower(trim(preg_replace('/\\(.*?\\)|\\[.*?\\]/s','',$item['name'])));
                $item['name'] = $pts . $item['name'];

                $item['rates'] = trim(str_replace(array("x"), "" , $article->find('li.rates', 0)->plaintext));
                $item['chronicle'] = trim($article->find('li.chronicles', 0)->plaintext);
                $item['date'] = trim($this->pars_time($article->find('li.date', 0)->plaintext));

                unset($article);


                $this->temp_base_server_list[$url_site][$item['date']] = $item;


            }
            unset($ul_server);
        }
    }







}


public function pars_time($time_formated){

    if(strripos($time_formated, " в ")){
        $temp = explode(" в " , $time_formated);
        $date = $temp[0];
        $time = $temp[1];
        $time = explode(":" , $time);
        //заглушка на удаление времени
        $time[0] = 0;
        $time[1] = 0;


        switch ($date){
            case "завтра";
                $date  = mktime((int)$time[0], (int)$time[1], 0, (int)date("m")  , (int)date("d")+1, (int)date("Y"));
                break;
            case "сегодня";
                $date  = mktime((int)$time[0], (int)$time[1], 0, (int)date("m")  , (int)date("d"), (int)date("Y"));
                break;
            case "вчера";
                $date  = mktime((int)$time[0], (int)$time[1], 0, (int)date("m")  , (int)date("d")-1, (int)date("Y"));
                break;
            default:
                $date = explode("." , $date);
                $date  = mktime((int)$time[0], (int)$time[1], 0, (int)$date[1]  , (int)$date[0], (int)$date[2]);
                break;
        }

    }else{

        switch ($time_formated){
            case "Завтра";
                $date  = mktime((int)0, (int)0, 0, (int)date("m")  , (int)date("d")+1, (int)date("Y"));
                break;
            case "Сегодня";
                $date  = mktime((int)0, (int)0, 0, (int)date("m")  , (int)date("d"), (int)date("Y"));
                break;
            case "Вчера";
                $date  = mktime((int)0, (int)0, 0, (int)date("m")  , (int)date("d")-1, (int)date("Y"));
                break;
            default:
                $date = explode("." , $time_formated);
                $date  = mktime((int)0, (int)0, 0, (int)$date[1]  , (int)$date[0], (int)$date[2]);
                break;
        }

    }



    return $date;
}

}`

CodeIgniter 4 version
Last bild

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions