Page not available when using SplFixedArray

时间:2015-06-30 13:45:17

标签: php oop pdo resultset

I'm getting "Page not available" if I run the following code:

namespace Database;
class Table extends \Database\Connection {
    // ...

    /**
     * Execute query and return result
     * @param type $query
     * @param type $sqlWildcards
     * @return SplFixedArray ResultSet
     */
    public static function query($query, $sqlWildcards = array()) {
        // Do some query stuff
        // $stmt is a PHP PDO Statement

        // Additional result manipulation
        $rowCount = 0;
        $rsStorage = new \SplFixedArray(500000);
        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
            $modRow = static::modifyRow($row);
            if ($modRow !== false) {
                $rsStorage[$rowCount] = $modRow;
                $rowCount++;
            }
        }

        // Resize 
        $rsStorage->setSize($rowCount);
    }
}

Method modifyRow($row):

/**
 * Gives the possibility to modify a result for child classes 
 * @param array $row
 * @return array
 */
protected static function modifyRow($row) {
    return $row;
}

But if I do the following:

    while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
        //$modRow = static::modifyRow($row);
        //if ($modRow !== false) {
            $rsStorage[$rowCount] = $modRow;
            $rowCount++;
        //}
    }

Everything works fine!

Edit: The test above makes no sense, I forgot to set $modRow to $row - this fails as well.

Another hint: if I do something like this

    while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
        $modRow = static::modifyRow($row);
        if ($modRow !== false) {
            $rsStorage[$rowCount] = $modRow;
            $rowCount++;
        }

        // Works
        if($rowCount == 5000) { break; }

        // Crashes (Page not available
        if($rowCount == 10000) { break; }
    }

Error reporting is activated but there's no internal server error, though. Just "page not available"

Edit: 9742 is the magic number. When $rowCount hits 9743 it crashes - doesn't matter if I test it from 0 to 9743 or 9744 to x

Edit2: If I use array instead of SplFixedArray everything's fine. Does not make sense since splfixedarray is more memory efficient than array()

Edit3: I wrote the memory usage into a file until the script crashes, it reaches a peak of 54MB - server limit is 128MB

Edit4: Apache log shows me a 'zend_mm_heap corrupted'

Never had this before, also google could not help me Any idea?

0 个答案:

没有答案