|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi
APC doesn't like it when I store the output of a SELECT: === include("apc.php"); $dbh = new PDO("sqlite:./test.sqlite"); $sql = "CREATE TABLE IF NOT EXISTS mytable (name TEXT)"; $dbh->exec($sql); $sql = "INSERT INTO mytable VALUES (?)"; $insert = $dbh->prepare($sql); $insert->execute(array("dead")); $sql = "INSERT INTO mytable VALUES (?)"; $insert = $dbh->prepare($sql); $insert->execute(array("beef")); $sql = "SELECT * FROM mytable"; store("rows",$dbh->query($sql)); $rows = fetch("rows"); foreach($rows as $row) { print $row['name'] . "<p>"; } $dbh = null; === PHP Fatal error: Uncaught exception 'PDOException' with message 'You cannot serialize or unserialize PDOStatement instances' in /usr/local/www/apache22/data/apc.php:9\nStack trace:\n#0 [internal function]: PDOStatement->__sleep()\n#1 /usr/local/www/apache22/data/apc.php(9): apc_store('rows', Object(PDOStatement), 0)\n#2 /usr/local/www/apache22/data/test.php(21): store('rows', Object(PDOStatement))\n#3 {main}\n thrown in /usr/local/www/apache22/data/apc.php on line 9 === Does it mean that PDO won't work with APC, and I should look at another caching tool? Thank you. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Gilles Ganault wrote:
> Hi > > APC doesn't like it when I store the output of a SELECT: > > <snip> > > Does it mean that PDO won't work with APC, and I should look at > another caching tool? > > Thank you. Before an object is stored it has to be serialized. Generally, internal classes (like PDOStatement) cannot be serialized. It seems like what you want to do is store an array of the rows, which is perfectly possible. Just use $dbh->query(...)->fetchAll() or something similar. The query() method returns a PDOStatement object - while it can be iterated using foreach (thanks to SPL) it is not an array and cannot be serialized. Jeremy |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Sat, 29 Mar 2008 20:54:08 -0700, Jeremy <jeremy@pinacol.com> wrote:
>It seems like what you want to do is store an array of the rows, which >is perfectly possible. Just use $dbh->query(...)->fetchAll() or >something similar. Thanks for the tip. This code works: $sql = "SELECT * FROM mytable"; $sth = $dbh->prepare($sql); $sth->execute(); store("rows",$sth->fetchAll()); $rows = fetch("rows"); foreach($rows as $row) { print $row['name'] . "<p>"; } |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Sun, 30 Mar 2008 13:26:45 +0200, Gilles Ganault <nospam@nospam.com>
wrote: >Thanks for the tip. This code works: It works, but according to "ab", it's much slower to use APC than hitting the SQLite file directly :-/ ======== # ab -kc 10 -t 30 http://localhost/test_apc.php Percentage of the requests served within a certain time (ms) 50% 105 66% 1054 75% 2066 80% 3089 90% 4347 95% 8136 98% 10140 99% 12148 100% 13115 (longest request) ======== # ab -kc 10 -t 30 http://192.168.0.2/test_direct.php Percentage of the requests served within a certain time (ms) 50% 29 66% 30 75% 31 80% 32 90% 2038 95% 6072 98% 14049 99% 17056 100% 17199 (longest request) ======== Does APC start making sense with a lot more users, or is SQLite just much faster than MySQL? |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Gilles Ganault wrote:
> On Sun, 30 Mar 2008 13:26:45 +0200, Gilles Ganault <nospam@nospam.com> > wrote: >> Thanks for the tip. This code works: > > It works, but according to "ab", it's much slower to use APC than > hitting the SQLite file directly :-/ > > ======== > # ab -kc 10 -t 30 http://localhost/test_apc.php > > Percentage of the requests served within a certain time (ms) > 50% 105 > 66% 1054 > 75% 2066 > 80% 3089 > 90% 4347 > 95% 8136 > 98% 10140 > 99% 12148 > 100% 13115 (longest request) > ======== > # ab -kc 10 -t 30 http://192.168.0.2/test_direct.php > > Percentage of the requests served within a certain time (ms) > 50% 29 > 66% 30 > 75% 31 > 80% 32 > 90% 2038 > 95% 6072 > 98% 14049 > 99% 17056 > 100% 17199 (longest request) > ======== > > Does APC start making sense with a lot more users, or is SQLite just > much faster than MySQL? > This is off topic in this newsgroup. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
![]() |
| Outils de la discussion | |
|
|