Connecting Tech Pros Worldwide Forums | Help | Site Map

Is PDO incompatible with caching mechanismes like APC?

Gilles Ganault
Guest
 
Posts: n/a
#1: Mar 30 '08
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.

Gilles Ganault
Guest
 
Posts: n/a
#2: Mar 30 '08

re: Is PDO incompatible with caching mechanismes like APC?


On Sat, 29 Mar 2008 20:54:08 -0700, Jeremy <jeremy@pinacol.comwrote:
Quote:
>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>";
}
Gilles Ganault
Guest
 
Posts: n/a
#3: Mar 30 '08

re: Is PDO incompatible with caching mechanismes like APC?


On Sun, 30 Mar 2008 13:26:45 +0200, Gilles Ganault <nospam@nospam.com>
wrote:
Quote:
>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?
Jerry Stuckle
Guest
 
Posts: n/a
#4: Mar 30 '08

re: Is PDO incompatible with caching mechanismes like APC?


Gilles Ganault wrote:
Quote:
On Sun, 30 Mar 2008 13:26:45 +0200, Gilles Ganault <nospam@nospam.com>
wrote:
Quote:
>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
==================

Closed Thread