j4mie / idiorm

A lightweight nearly-zero-configuration object-relational mapper and fluent query builder for PHP5.
http://j4mie.github.com/idiormandparis/
2.01k stars 369 forks source link

Mysql server goes away when Idiorm's record updates #157

Closed tashemi closed 11 years ago

tashemi commented 11 years ago

I have a script where user can attach file to the record. File is stored separately (not in a database). When user does not attach file and click on "Save record" it works fine. When user attaches file it does next steps:

  1. File uploads correct
  2. Script takes from DB record details using Idiorm ($dbItem)
  3. Script updates field "filesize" on the record ($dbItem->Size = "28 Mb")
  4. Script tries to save record, and I get this:

    PDOException
    
    Code: HY000
    
    Message: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
    
    File: /home/../includes/idiorm.php
    
    Line: 1675

I found out 2 things:

  1. script returns "General error: 2006 MySQL server has gone away" only when uploaded file is bigger than 20 Mb and I try to update database with $dbRecord->save(). Sql query generated by Idiorm:
UPDATE `downloads` SET `Text` = 'Product caption', `Status` = 'Normal', `Type` = 'Demoversion / Release', `Size` = '28.05 MB' WHERE `downloadID` = '14'
  1. script does not return "General error: 2006 MySQL server has gone away" when uploaded file is bigger than 20 Mb and I do not try to update record.
  2. I can upload file bigger than 20 Mb and run raw query with Idiorm::raw_exec() and catch no error.

Does Idiorm do something wrong?

tashemi commented 11 years ago

The Problem was the "wait timeout" setting in MySQL. But still it is interesting why plain sql via raw_exec() works fine and update via save method on Idiorm object causes delay that Mysql goes away. Is it so big difference in performance?

treffynnon commented 11 years ago

No. This is because Idiorm opens a connection (https://github.com/j4mie/idiorm/blob/master/idiorm.php#L225) for all it's interactions and re-uses (https://github.com/j4mie/idiorm/blob/master/idiorm.php#L1592) that connection. raw_execute() on the other hand opens a connection each time it is called (https://github.com/j4mie/idiorm/blob/master/idiorm.php#L373).

tashemi commented 11 years ago

@treffynnon thanks for response. now reason of this error looks completely clear for me.