PHP pthreads and SQLite3


PHP pthreads and SQLite3

更新

我发现这不是SQLite的问题
看看这个

代码1

<?php
class Test
{
    protected $member;
    public function __construct($member = null)
    {
        $this->member = $member;
        $this->member->text = 'changed text';
    }
}
class Text
{
    public $text = 'this is text';
}
$text = new Text();
$test = new Test($text);
echo $text->text.PHP_EOL;

输出1

changed text

代码2

<?php
class Test extends Thread  // Difference
{
    protected $member;
    public function __construct($member = null)
    {
        $this->member = $member;
        $this->member->text = 'changed text';
    }
}
class Text
{
    public $text = 'this is text';
}
$text = new Text();
$test = new Test($text);
echo $text->text.PHP_EOL;

输出2

this is text

并且启用了php线程安全。(来自phpinfo)
这是php故障吗?

原件

我在php中使用SQLite3时遇到了一些线程问题
代码是简单的

<?php
class Test
{
    protected $db;
    public function __construct()
    {
        $this->db = new SQLite3(__DIR__.'/test.db');
        echo $this->db->lastErrorCode().PHP_EOL;
    }
}
$test = new Test();

output : 0

上面的代码运行良好
但下面的代码不起作用,它只是扩展了线程

<?php
class Test extends Thread
{
    protected $db;
    public function __construct()
    {
        $this->db = new SQLite3(__DIR__.'/test.db');
        echo $this->db->lastErrorCode().PHP_EOL;
    }
}
$test = new Test();

output : PHP警告:SQLite3::lastErrorCode():SQLite3对象未在/home/ordinaryparksee/Projects/human/test.PHP第8行正确初始化警告:SQLite3::lastErrorCode():SQLite3对象未在第8行上的/home/ordinaryparksee/Projects/human/test.php中正确初始化

怎么了??

来源:https://stackoverflow.com/a/14565559/3333776

在介绍页上的手册中,它指出任何对象旨在由多个上下文操纵的可堆叠、线程或Worker,如

<?php
class Test extends Thread  // Difference
{
    protected $member;
    public function __construct($member = null)
    {
        $this->member = $member;
        $this->member->text = 'changed text';
    }
}
class Text extends Threaded  // Difference2
{
    public $text = 'this is text';
}
$text = new Text();
$test = new Test($text);
echo $text->text.PHP_EOL;