Is PDO incompatible with caching mechanismes like APC?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gilles Ganault

    Is PDO incompatible with caching mechanismes like APC?

    Hi

    APC doesn't like it when I store the output of a SELECT:

    ===
    include("apc.ph p");

    $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",$d bh->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\nStac k trace:\n#0 [internal
    function]: PDOStatement->__sleep()\n# 1
    /usr/local/www/apache22/data/apc.php(9): apc_store('rows ',
    Object(PDOState ment), 0)\n#2
    /usr/local/www/apache22/data/test.php(21): store('rows',
    Object(PDOState ment))\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

    #2
    Re: Is PDO incompatible with caching mechanismes like APC?

    On Sat, 29 Mar 2008 20:54:08 -0700, Jeremy <jeremy@pinacol .comwrote:
    >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",$s th->fetchAll());

    $rows = fetch("rows");
    foreach($rows as $row) {
    print $row['name'] . "<p>";
    }

    Comment

    • Gilles Ganault

      #3
      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?

      Comment

      • Jerry Stuckle

        #4
        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@attgl obal.net
        =============== ===

        Comment

        Working...