Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Memory exhausted when creating a MySQL adapter instance

Hello!

I recently got a strange error on my production servers (which are luckily not live yet) that suddenly appeared.

The error message is this: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted

On the line reported, I have the database adapter setup for the DependencyInjector:

$dbAdapter = new Mysql(
    array(
        "host" => $dbConfig["host"],
        "dbname" => $dbConfig["database"],
        "username" => $dbConfig["user"],
        "password" => $dbConfig["password"],
        "charset" => "utf8"
    )
);

I've dumped the $dbConfig-variable which contains the proper information, with which I can connect manually to the database. I have also upped the memory limit, and this just exhausts any memory I allocate.

Can anyone help me troubleshoot this?

Thank you!

// dimhoLt

EDIT: I am also getting this error when running Model::find() from my unit tests, but not my dev server. What's going on??

EDIT2: It appears that I may be on to something. I had not set up my testing user database settings properly, so the testing environment didn't manage to connect to the database. Also, it seems that my sysadmin had set up database replication with a new database IP address on the production servers, breaking my database settings there as well. I will be able to fix this tomorrow and will get back with the results. I will still keep this issue open until I've tested that though since I used to receive the error message from the database (could not connect, access denied or similar, instead of memory exhaustion which I now get).



14.0k
Accepted
answer
edited Nov '14

I have now found the cause of this issue.

I tried to create a file with no Phalcon connection, but with a vanilla PDO object set up using the config file for my Phalcon application (vanilla PHP array) for the database information, and I got the error message Could not find driver.. Why this arose now, I cannot say, but I simply re-installed the driver ($ sudo apt-get install php5-mysql for those of you who wonder) and my Phalcon app ran beautifully.

Now, I'd still love some clarification from the Phalcon staff as of why no Exception was thrown, or error issued for this by any Phalcon object (adapter / model)? The \Phalcon\Db\Adapter\MySQL or the \Phalcon\Mvc\Model::find() methods simply consumed all available memory and crashed. Is this a bug, or have I made some kind of misconfiguration to trigger this strange behavior?

Thank you for your time, everyone who checked my issue. I hope this answer helps others.

Cheers.