2014-03-30 00:08
浏览 40


So i have pthreads working with PHP on windows, but how can i compile and run my pthreads implementations with phalanger 3.0? At the moment, it builds with 0 errors / 0 warnings, but then when i run it it says

CompileError: The class 'ThreadTest' is incomplete - its base class or interface is unknown in C:\phptests\thread.php on line 10, column 1.

I see in the Phalanger install dir it has the php extensions .dll's; and the php_pthreads zip i downloaded it has .pdb intermediate files for the pthreads .dll's, so is there a way to get Phalanger to compile and run pthreads?

图片转代码服务由CSDN问答提供 功能建议

所以我在Windows上使用pthreads与PHP合作,但是如何使用phalanger 3.0编译和运行我的pthreads实现? 目前,它构建0错误/ 0警告,但是当我运行它时它说

  CompileError:类'ThreadTest'不完整 - 它的基类或 接口在第10行第1列的C:\ phptests \ thread.php中是未知的。

我在Phalanger安装目录中看到它有php扩展名.dll的 ; 和我下载的php_pthreads zip有ppreads .dll的.pdb中间文件,所以有没有办法让Phalanger编译并运行pthreads?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dopii22884 2014-03-30 10:22

    Phalanger does not have a support for pthreads.

    You can use .NET alternatives via clr_create_thread(callback [, parameters]) function or sb. has to implement missing support for pthreads in C#.

    clr_create_thread is bit misleading name though, as it doesn't really create a thread. Instead it takes your callback and schedules it for execution on a ThreadPool. Threads on a thread pool are somewhat special as they do not end when your callback ends. Instead they are reused for later requests (like if you call clr_create_thread again the callback execution may end up on the thread you used previously). As such, there's little sense in Joining ThreadPool threads, as they do not end voluntarily. However, you may use other .net synchronization mechanisms if you want to wait for your callback(s) to finish (AutoResetEvent and WaitHandle::WaitAll are the important parts):

    use System\Threading;
    class ThreadTest
        public static function main()
            (new self)->run();
        public function run()
            $that = $this;
            $finished = [];
            for ($i = 0; $i < 5; $i++) {
                $finished[$i] = new Threading\AutoResetEvent(false);
                clr_create_thread(function() use ($that, $finished, $i) {
            echo "Main ended
        public function inathread()
            $limit = rand(0, 15);
            $threadId = Threading\Thread::$CurrentThread->ManagedThreadId->ToString();
            echo "
     thread $threadId limit: " . $limit . " 
            for ($i = 0; $i < $limit; $i++) {
                echo "
     thread " . $threadId . " executing 
            echo "
     thread $threadId ended 
    打赏 评论

相关推荐 更多相似问题