Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tried to allocate #1578

Closed
demortx opened this issue Dec 3, 2018 · 6 comments
Closed

tried to allocate #1578

demortx opened this issue Dec 3, 2018 · 6 comments

Comments

@demortx
Copy link

demortx commented Dec 3, 2018


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

@InsiteFX
Copy link
Contributor

InsiteFX commented Dec 3, 2018

Check your php.ini file for memory size.

; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 256M

@demortx
Copy link
Author

demortx commented Dec 3, 2018

I increased it to 15 gigabytes of RAM

@puschie286
Copy link
Contributor

pls update your code - /var/www/web.ru/system/Debug/Exceptions.php on line 195 is not an valid code line, so it looks like your code is outdated. its hard to make any assumptions without knowing your version

https://github.com/codeigniter4/CodeIgniter4/blob/v4.0.0-alpha.2/system/Debug/Exceptions.php
https://github.com/codeigniter4/CodeIgniter4/blob/v4.0.0-alpha.3/system/Debug/Exceptions.php

@demortx
Copy link
Author

demortx commented Dec 4, 2018

i use the latest version https://github.com/codeigniter4/CodeIgniter4

@demortx
Copy link
Author

demortx commented Dec 10, 2018

Understood what the problem was, did not pass the parameters in the Services when accessing return static :: getSharedInstance ('Telegram', $ token);

Can be closed

@lonnieezell
Copy link
Member

Glad you found the problem! Closing, then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants