• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fatal Memory Error in version 3.1.6+

#1
I have never been able to migrate from 3.1.5 to 3.1.6 because of the following error

==================
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in /var/www/html/rtsusers/system/core/Loader.php on line 1205

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

===================

I discovered that the problem lies in the file /system/core/Loader.php

If I edit everything in the /system/core/Loader.php in the version 3.1.5 to look like /system/core/Loader.php in 3.1.11 then all edits cause no problem except the following in the new version.

Code:
// =========== from line 1046... /system/core/Loader.php in 3.1.11 CAUSES FATAL MEMORY ERROR ===========
// Safety: Was the class already loaded by a previous call?
if (class_exists($class, FALSE))
{
$property = $object_name;
if (empty($property))
{
$property = strtolower($class);
isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property];
}

$CI =& get_instance();
if (isset($CI->$property))
{
log_message('debug', $class.' class already loaded. Second attempt ignored.');
return;
}

return $this->_ci_init_library($class, '', $params, $object_name);
}

// Let's search for the requested library file and load it.
foreach ($this->_ci_library_paths as $path)
{
// BASEPATH has already been checked for
if ($path === BASEPATH)
{
continue;
}

$filepath = $path.'libraries/'.$subdir.$class.'.php';
// Does the file exist? No? Bummer...
if ( ! file_exists($filepath))
{
continue;
}

include_once($filepath);
return $this->_ci_init_library($class, '', $params, $object_name);
}

Code:
// =========== /system/core/Loader.php in 3.1.5 WORKS WITHOUT ANY PROBLEM ===========

// Let's search for the requested library file and load it.
foreach ($this->_ci_library_paths as $path)
{
// BASEPATH has already been checked for
if ($path === BASEPATH)
{
continue;
}

$filepath = $path.'libraries/'.$subdir.$class.'.php';

// Safety: Was the class already loaded by a previous call?
if (class_exists($class, FALSE))
{
// Before we deem this to be a duplicate request, let's see
// if a custom object name is being supplied. If so, we'll
// return a new instance of the object
if ($object_name !== NULL)
{
$CI =& get_instance();
if ( ! isset($CI->$object_name))
{
return $this->_ci_init_library($class, '', $params, $object_name);
}
}

log_message('debug', $class.' class already loaded. Second attempt ignored.');
return;
}
// Does the file exist? No? Bummer...
if ( ! file_exists($filepath))
{
continue;
}

include_once($filepath);
return $this->_ci_init_library($class, '', $params, $object_name);
}

Please help me.

EDIT: code tags added for readability. See MyCode


Attached Files
.php   YESworking.php (Size: 36.26 KB / Downloads: 2)
.php   NOTworking.php (Size: 36.21 KB / Downloads: 0)
.html   ERRORmessage.html (Size: 273 bytes / Downloads: 2)
Reply

#2
Can you provide us with some sample code on how you load a library?

Possible as small as possible that will trigger this error, remove everything in your code except the code that triggers this error and post it here.
Also post how you named them and where you stored them.
Reply

#3
You are right! The problem is something to with loading of library. I commented off each line that loads a library and the error went away.

So how should I load a library? This is how I have been loading...

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Roots extends CI_Controller {

public function __construct()
{
parent::__construct();
$this->load->library('base');
$this->load->library('utilities');
$this->load->library('session');
$this->load->library('auth');
}

public function start()
{
}
}
Reply

#4
@owino,

You could also increase your memory limit in the PHP.ini file. Sometimes it may not be the code it may be the fact that you have exceeded the default PHP settings. I've run into similar situations and realized that I needed to increase the default PHP settings.
Reply

#5
I am not a comfortable with editing third party code.

The culprit must be those few lines that were introduced at 3.1.6.

As I wait to eventually migrate to version 4 when it is ripe (I hope migration will not be a pain), I will stick with version 3.1.5 which is working well.
Reply

#6
I would use the php.ini setting below.

PHP Value:
php_value memory_limit 256M

PHP.INI
memory_limit = 256M

Or in Code:
ini_set("memory_limit", "256M");
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#7
@owino
Does it happen if you just tries to load just one library?
Have you tried loading different libraries to see if all are failing or just one?

If you haven't made a custom session library try to load this one:
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Test extends CI_Controller {

    public function 
__construct()
    {
        
parent::__construct();
        
$this->load->library('session');
    }


Also for debugging purposes upload the latest version of CI on your server and set it up like a new application. Can you load the session library now?

What PHP version are you using? It may not be 100% compatible, consider upgrading or changing version.

@php_rocs and @InsiteFX: If he can't even load one library it can't be memory issue. He already have ~128MB of RAM (if it's not shared).
Reply

#8
(10-08-2019, 10:40 AM)jreklund Wrote: @owino
Does it happen if you just tries to load just one library?
Have you tried loading different libraries to see if all are failing or just one?

If you haven't made a custom session library try to load this one:
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Test extends CI_Controller {

    public function 
__construct()
    {
        
parent::__construct();
        
$this->load->library('session');
    }


Also for debugging purposes upload the latest version of CI on your server and set it up like a new application. Can you load the session library now?

What PHP version are you using? It may not be 100% compatible, consider upgrading or changing version.

@php_rocs and @InsiteFX: If he can't even load one library it can't be memory issue. He already have ~128MB of RAM (if it's not shared).

I have a custom session library. Could this be causing any problem?

Even one library does not load. Here is my platform:

Database server
    Server: Localhost via UNIX socket
    Server type: MariaDB
    Server connection: SSL is not being used Documentation
    Server version: 10.3.17-MariaDB - MariaDB Server
    Protocol version: 10
    User: root@localhost
    Server charset: cp1252 West European (latin1)

Web server
    Apache/2.4.41 (Fedora)
    Database client version: libmysql - mysqlnd 5.0.12-dev - 20150407 - $Id: 7cc7cc96e675f6d72e5cf0f267f48e167c2abb23 $
    PHP extension: mysqliDocumentation curlDocumentation mbstringDocumentation
    PHP version: 7.3.10
Reply

#9
Have you tried a clean CodeIgniter without your code and just loading a library?

Just tried to autoload session in /application/config/autoload.php in a clean CI 3.1.11 with PHP 7.3.10 and works fine here.

That dosen't work for you?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.