PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Is PDO incompatible with caching mechanismes like APC?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Is PDO incompatible with caching mechanismes like APC?

Réponse
 
LinkBack Outils de la discussion
Vieux 30/03/2008, 03h36   #1
Gilles Ganault
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Is PDO incompatible with caching mechanismes like APC?

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.
  Réponse avec citation
Vieux 30/03/2008, 04h54   #2
Jeremy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is PDO incompatible with caching mechanismes like APC?

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
  Réponse avec citation
Vieux 30/03/2008, 12h26   #3
Gilles Ganault
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is PDO incompatible with caching mechanismes like APC?

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>";
}
  Réponse avec citation
Vieux 30/03/2008, 13h13   #4
Gilles Ganault
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is PDO incompatible with caching mechanismes like APC?

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?
  Réponse avec citation
Vieux 30/03/2008, 14h56   #5
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is PDO incompatible with caching mechanismes like APC?

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
==================

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 00h12.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14920 seconds with 13 queries