如何在线程PHP中编写文本文件

时间:2018-03-01 04:43:41

标签: php pthreads

我无法使用php pthreads扩展在线程中编写文本文件。但是同一段代码可以成功执行DB插入操作。有人能帮助我吗? PHP版本:5.6 请参阅以下代码并提出所需的更改建议:

class MyThread extends Thread
{
    private $wallet;
    private $std;
    public function __construct($wallet,$std)
    {
        $this->wallet = $wallet;
        $this->std = $std;
    }
    public function run()
    {
        $conn = new mysqli("localhost", "root", "", "test");
        if ($conn->connect_error) 
        {
            die("Connection failed: " . $conn->connect_error);
        } 
            $sql = "INSERT INTO test1 (data) VALUES ('TID:".Thread::getCurrentThreadId()."')";
            $conn->query($sql);
            file_put_contents("abc.txt","ABCD");
    }
}
$wallet = "ABC";
$std = "DEF";
$pool = new MyThread($wallet,$std);
$pool->start();

先谢谢你。 :)

0 个答案:

没有答案