php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57191 Apache Segfaults when storing PDO statements in static variables
Submitted: 2006-08-21 12:10 UTC Modified: 2006-10-25 17:33 UTC
From: wolff at 21st dot de Assigned:
Status: Closed Package: APC (PECL)
PHP Version: 5.1.4 OS: Ubuntu Dapper
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: wolff at 21st dot de
New email:
PHP Version: OS:

 

 [2006-08-21 12:10 UTC] wolff at 21st dot de
Description:
------------
This is with APC 3.0.10 - I'm storing a prepared statement 
object in a static object variable to act as a statement 
cache. When I do that, PHP seems to make a clean exit, but 
Apache segfaults and just displays a blank page.

This seems not to occur on the first request after a fresh 
Apache restart, though - but on all subsequent ones.

Additional discussion of the bug can be found here:
http://blog.wolff-hamburg.de/index.php?url=archives/9-UPDATE-Bug-found-kinda.html
...only I came to the conclusion that it was APC's 
wrong-doing after I already submitted the blog post.

Bug *may* be somehow related to this one:
http://pecl.php.net/bugs/bug.php?id=8324

...but for me it only happens when storing prepared 
statements in static variables.

Reproduce code:
---------------
class SegFault {
    static protected $cache = array();
    public function execute() {
        $pdo = new PDO('mysql:host=localhost;dbname=mysql', 'root');
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $stmt = $pdo->prepare('SELECT user FROM user WHERE host=:hostname');
        self::$cache[] = $stmt; // this is the culprit, remove this line and all is well
        
        $bindings = array(':hostname' => 'localhost');
        $stmt->execute($bindings);
        return $stmt;
    }    
}

$crash = new SegFault();
echo "<p>Timestamp: ".time()."</p><pre>";
foreach($crash->execute() as $row) {
    print_r($row);
}
echo "</pre>";

Expected result:
----------------
A page should be served containing the current timestamp 
and a printout of all MySQL users for localhost.

Actual result:
--------------
Apache segfaults:
[Mon Aug 21 17:40:58 2006] [notice] child pid 27755 exit 
signal Segmentation fault (11)

Either disabling APC or commenting out the line "self::
$cache[] = $stmt;" will fix the problem.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-21 12:15 UTC] rasmus@php.net
Right, so please try 3.0.11
 [2006-08-21 17:56 UTC] gopalv82 at yahoo dot com
A direct duplicate of http://bugs.php.net/bug.php?id=37445 ?

Here's the patch, apply and retest - http://news.php.net/php.cvs/39679.

APC probably doesn't have anything to do with this particular bug :)
 [2006-08-23 08:04 UTC] wolff at 21st dot de
Ok, I installed APC 3.0.11 now (sorry for not trying this 
earlier) and I still get the exact same behavior.
 [2006-08-29 00:24 UTC] gopalv82 at yahoo dot com
Please upgrade your php build. This is a known bug which was introduced in 5.1.4 and fixed in 5.1.6.

Please feel free to ask for this bug to re-opened if the problem persists.
 [2006-10-10 16:41 UTC] florian dot herlitschke at creaflex dot de
I just got the same error and created a test case

$test = new test();
echo "hello world";

class test
{
  public function __construct() 
  {
    $dsn = 'mysql:host=localhost;dbname=mydb';
    $dbh = new PDO($dsn,'foo','****');
    $x = $dbh->prepare('SELECT * FROM table');
    self::$cache = $x; // remove me
  }
}


deactivating apc didnt work. First request after apache restart works well, second request end up with a blank page. PHP Version 5.1.6-pl4-gentoo with (or without) APC 3.0.12p2
 [2006-10-10 17:03 UTC] florian dot herlitschke at creaflex dot de
Sorry, my fault, deactivating APC works pretty well for my example. But with activated APC I have to restart Apache or edit my script with a space or a blank line to get it work once again! But only for one request!

Apache error_log says:
[Tue Oct 10 23:13:57 2006] [notice] child pid 15218 exit signal Segmentation fault (11)
 [2006-10-11 02:04 UTC] gopalv82 at yahoo dot com
Moving back to Open.

Thanks for the update.
 [2006-10-11 07:26 UTC] gopalv82 at yahoo dot com
Actually this is not really APC's wrong-doing.

There seems to be some code in PDO land which depends on the destroy_class cleaning up static members before the standard deactivation cleanups start.

I'm investigating on how to fix this in both places.
 [2006-10-25 17:33 UTC] gopalv82 at yahoo dot com
This patch fixes the APC part of the story

http://news.php.net/php.pecl.cvs/6545

This "fixes" the segv by re-ordering the destructors, though not the correct fix, still prevents a few memory leaks (if nothing else).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 10:01:33 2025 UTC