Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wxPHP线程应用程序因0xc0000005异常而崩溃_Php_Multithreading_Nullpointerexception_Wxwidgets_Wxphp - Fatal编程技术网

wxPHP线程应用程序因0xc0000005异常而崩溃

wxPHP线程应用程序因0xc0000005异常而崩溃,php,multithreading,nullpointerexception,wxwidgets,wxphp,Php,Multithreading,Nullpointerexception,Wxwidgets,Wxphp,我正试图用wxPHP编写一个简单的应用程序,使用exec('ping')命令从文件ping ip 我希望结果在后台ping时一个接一个地显示在GUI中,因此我在线程中执行exec('ping')命令 但我有非常奇怪的错误和行为。问题是我不能重现错误。有时这个程序运行得非常好。有时它在线程中崩溃。有时它在发送事件时崩溃。等等 以下是从命令行运行程序时出现的错误: C:\Users\SH\Desktop>wxphp pinger.wxphp PHP Notice: Undefined pro

我正试图用wxPHP编写一个简单的应用程序,使用
exec('ping')
命令从文件ping ip

我希望结果在后台ping时一个接一个地显示在GUI中,因此我在线程中执行
exec('ping')
命令

但我有非常奇怪的错误和行为。问题是我不能重现错误。有时这个程序运行得非常好。有时它在线程中崩溃。有时它在发送事件时崩溃。等等

以下是从命令行运行程序时出现的错误:

C:\Users\SH\Desktop>wxphp pinger.wxphp
PHP Notice:  Undefined property: wxHtmlWindow::$parent in Unknown on line 0
PHP Fatal error:  Call to a member function setPingResults() on null in Unknown
on line 0

C:\Users\SH\Desktop>wxphp pinger.wxphp
PHP Notice:  Undefined property: wxHtmlWindow::$parent in Unknown on line 0
PHP Fatal error:  Call to a member function setPingResults() on null in Unknown
on line 0

C:\Users\SH\Desktop>wxphp pinger.wxphp
PHP Notice:  Undefined property: wxHtmlWindow::$parent in Unknown on line 553649674
PHP Fatal error:  Call to a member function setPingResults() on null in Unknown
on line 553649674
这是我的代码:

<?php

if(!extension_loaded('wxwidgets'))
{
    dl('wxwidgets.' . PHP_SHLIB_SUFFIX);
}

define('EVT_PINGDONE',wxNewEventType());


class myPing extends wxThread
{
    function __construct($parent)
    {
        parent::__construct(wxTHREAD_JOINABLE);

        $this->parent =  $parent;
    }

    function Entry()
    {
        $addresses = file($this->parent->btnBrowse->GetPath(),FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
        foreach($addresses as $k => $address){

            $results = exec("ping $address");

            $this->parent->setPingResults($results);

            $evt = new wxCommandEvent(EVT_PINGDONE);
            $this->parent->QueueEvent($evt);
        }

        $this->parent->onThreadDone();

        return;
    }
}

class mythFrame extends wxFrame {

    function __construct( $parent=null ){
        parent::__construct ( $parent, wxID_ANY, 'Pinger', wxDefaultPosition, new wxSize( 600,400 ), wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );

        $this->SetSizeHints( wxDefaultSize, wxDefaultSize );

        $bSizer2 = new wxBoxSizer( wxHORIZONTAL );

        $this->button = new wxButton( $this, wxID_ANY, "Ping", wxDefaultPosition, new wxSize(300, 40), 0 );
        $bSizer2->Add($this->button, 0, wxALL|wxEXPAND, 5);

        $bSizer1 = new wxBoxSizer( wxVERTICAL );

        $this->btnBrowse = new wxFilePickerCtrl( $this, wxID_ANY, 'C:\Users\SH\Desktop\stuff\servers.txt', "Select a file", "*.*", wxDefaultPosition, wxDefaultSize, wxFLP_DEFAULT_STYLE );
        $bSizer1->Add( $this->btnBrowse, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 5 );

        $this->html = new wxHtmlWindow( $this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
        $bSizer1->Add( $this->html, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND, 5 );

        $bSizer1->Add( $bSizer2, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );

        $this->SetSizer( $bSizer1 );
        $this->Layout();

        $this->Centre( wxBOTH );

        // Connect Events
        $this->button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, array($this, "hndlrButton") );
        $this->Connect(wxEVT_TIMER, array($this, "onTimer"));
        $this->Connect(EVT_PINGDONE, array($this, 'updateText'));

        $this->pingThread = new myPing($this);
        $this->m_timer = new wxTimer($this);
        $this->pingResults = '';

    }

    function updateText($event){

        $this->html->AppendToPage($this->pingResults.'<br>');
    }

    function onTimer(){
        if($this->threadDone == true){
            $this->m_timer->Stop();
            $this->button->Enable();
            $this->btnBrowse->Enable();
            $this->html->AppendToPage('<br>Finished.<hr>');

            while($this->pingThread->IsRunning()){}
            $this->pingThread->Delete();

            $this->pingThread = new myPing($this);
        }
    }

    function onThreadDone(){
        $this->threadDone = true;
    }

    function setPingResults($results){
        $this->pingResults = $results;
    }


    function hndlrButton( $event ){
        $this->threadDone = false;
        $this->m_timer->start(3000);
        $this->button->Disable();
        $this->btnBrowse->Disable();

        $this->pingThread->Create();
        $this->pingThread->Run();
    }

}

$myFrame = new mythFrame();
$myFrame->show();
wxEntry();

?>
故障模块的变化取决于我是调用php函数还是调用线程
Entry()
中的
exec()
。但是异常代码总是
0xc000005

有一件奇怪的事情是错误是一致的,比如

Undefined property wxHtmlWindow::$parent 
如果你读了代码,你就会意识到根本没有这样的调用。实际上,
$parent
仅在线程中访问。线程中的其他函数也有类似的错误。应用程序似乎没有意识到它在线程中,线程中的
$this
指向主框架对象

我想我的代码或者wxPHP可能有严重的问题。这个程序昨晚不工作,今天早上开始工作。然后我添加了一个图标和一些背景色,它突然又给我错误了

其他信息

  • 不适用于:

    Windows 7-64位-wxphp-3.0.2.0-php5.6-x64.exe

    Windows 7-32位-wxphp-3.0.2.0-php5.4-x86

  • 示例
    thread.wxphp
    与wxphp捆绑的应用程序 这个包也不起作用
  • 但是,我的代码和示例应用程序在Linux上都可以正常工作(
    Linux)
    Mint-32位-php5-wxwidgets_3.0.2.0_i386
  • 当我从线程中删除
    exec()
    QueueEvent()
    Entry()
    我没有收到任何错误

有人知道这里发生了什么吗?

我是wxPHP的维护者,我建议使用PHP扩展进行多线程处理,因为该扩展可以正确处理PHP zendengine中的线程。wxPHP源代码生成器自动包装了wxThread类,它可能需要进一步开发才能正常工作。

谢谢JGM。我安装了pthreads,但在尝试访问线程中的GUI对象时遇到此错误:
致命错误:无法获取wxButton::GetLabel的本机对象。我在github上发现了一个类似的问题,您已经回答了这个问题。所以我安装了php-5.6-ts-x64和pthreads-5.6-ts-x64以及wxphp-5.6-ts-x64(PECL dll)的线程安全版本,但仍然出现相同的错误。我还从sourceforge安装了wxphp-3.0.0.0-x64-ts包,但这也给了我同样的错误。
Undefined property wxHtmlWindow::$parent