Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Session Issue
  • I am currently using FuelPHP 1.8.0.4 (core/auth/email/oil/orm/parser) and am looking to upgrade to the latest version of fuel/core 1.8.1.6. However, it seems that when I upgrade to any 1.8.1.x branch of fuel/core, my application stops working with a MySQL error: Fuel\Core\Database_Exception [ 2014 (2014) ]: Commands out of sync; you can't run this command now [ SELECT * FROM `fuelphp_session` WHERE `previous_id` = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' ]

    My application is currently storing sessions in the database as I have a multi-server setup running, so all servers need to be able to access the same session data. I did a little digging and it seems that the issue is specifically related to the way FuelPHP handles the database access to sessions. If I switch my config to store sessions in flat files, my application seems to run fine.

    The exception gets thrown in COREPATH/classes/database/mysqli/connection.php @ line 232 after trying to ping the connection $this->_connection->ping(). If I switch back to fuel/core 1.8.0.4, everything works fine again using the database.

    If you require more details, I can send you the full backtrace when this error occurs. Any help with this is greatly appreciated.
  • Can you switch the database type from "mysqli" to "mysql" in your db.php (which uses PDO), does the error still appear?
  • If I read the MySQL docs correctly, this error means a query is executed before the previous result is used and/or freed.

    Which suggests the result object doesn't free the result properly in all cases. Which result objects do you use, cached on non-cached (the "enable_cache" parameter on the db.php connection)?
  • Thanks for the fast response. I was indeed using mysqli. I switched it to PDO and the errors have gone away. Not quite sure why this is happening though. I do not have caching enabled for that database connection. When caching is enabled, mysqli connections seem to work fine.

    I also noticed that my app wasn't working properly after updating fuel/core to 1.8.1.6 while using mysqli. I have a module that fetches custom sites based on the URI, and that started throwing 404 exceptions. After I switched to PDO, it started working again.

    Would you recommend switching to pdo or sticking with mysqli with caching? Is there any reason why fuel/core 1.8.1 would cause mysqli to break like that when the 1.8.0 branches work fine?
  • HarroHarro
    Accepted Answer
    When you have caching disabled, the mysql result object is passed on to a Database result object, and data is fetched as you iterate over the result, and is only freed when all results are processed or the result object is destroyed. 

    This takes less memory with large datasets, as when you enable the cache, all results are fetched at once and stored in memory for the lifetime of the result object.

    I would definitely switch to PDO (we don't use anything else), the mysqli drivers aren't all then since PHP switched to the mysqldnd drivers (for example, it doesn't really support ping() which may also be the cause of your issue).
  •  Is there any reason why fuel/core 1.8.1 would cause mysqli to break like that when the 1.8.0 branches work fine?

    No clue, I've switched a few of our apps (which al run on develop code, we eat our dogfood ;-) from PDO to mysqli, but I don't see any errors.
  • Thanks a bunch for your help on this. I will switch over to the PDO driver in the next week or so after we do some testing on our platform with it. At least we can upgrade to a recent build of the Fuel framework by making this switch.

    BTW, FuelPHP is a great framework with some of the best support around. :)
  • Thanks for the kudos, we do our best. ;-)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion