搜索
首页php教程php手册PHP 线程安全,多线程

PHP 线程安全,多线程

Jun 06, 2016 pm 07:52 PM
phpphp.ini安全扩展添加线程

3.添加扩展 php.ini添加 : extension=pthreads.so; 如果你是之前安装过php,那么, /usr/local/php-zts/bin/php -i|grep php.ini 这个语句帮你找到php.ini位置。 找出php.ini的位置,修改它把ext=pthreads.so加入进入进去,因为我原来就有php,现在新装的php

3.添加扩展

php.ini添加 :  extension=pthreads.so;

如果你是之前安装过php,那么,/usr/local/php-zts/bin/php -i|grep "php.ini" 这个语句帮你找到php.ini位置。

找出php.ini的位置,修改它把ext=pthreads.so加入进入进去,因为我原来就有php,现在新装的php.ini文件不存在我就考了一个过去……


4.查看扩展是否安装成功

/usr/local/php5.5.12-zts/bin/php -i | grep -i pthreads




测试代码:

<?php

/*

* Sharing symbols 101

* @NOTE Thread::fetch was never included in a release and was superceeded by object handlers

*   pthreads allows read access to thread data from any context

    pthreads allows write access to thread data from any context

    carry on reading ...

    work in progress ...

*/ 

classTestObject { 

    public$val

   

classFetching extendsThread { 

    publicfunction run(){ 

        /*

        * of course ...

        */ 

        $this->sym = 10245; 

        $this->arr = array

            "1","2","3" 

        ); 

        echo'6'.chr(10); 

        /*

        * objects do work, no preparation needed ...

        * read/write objects isn't finalized ..

        * so do the dance to make it work ...

        */ 

        $obj= newTestObject(); 

        $obj->val = "testval"

        $this->obj = $obj

        echo'7'.chr(10); 

        /*

        * will always work

        */ 

        $this->objs = serialize($this->obj); 

        echo'8'.chr(10); 

        /*

        * nooooooo

        */ 

        $this->res = fopen("php://stdout","w"); 

        echo'9'.chr(10); 

        /*

        * tell the waiting process we have created symbols and fetch will succeed

        */ 

        $this->synchronized(function(){ 

            $this->notify(); 

        }); 

        echo'10'.chr(10); 

        /* wait for the process to be finished with the stream */ 

        $this->synchronized(function(){ 

            $this->wait(); 

        }); 

        echo'11'.chr(10); 

    

echo'0'.chr(10); 

$thread= newFetching(); 

echo'1'.chr(10); 

$thread->start(); 

//sleep(1); 加了这个就不能正常工作,真奇怪 

echo'2'.chr(10); 

$thread->synchronized(function($me){ 

    echo'3'.chr(10); 

    $me->wait(); 

    echo'4'.chr(10); 

},$thread); 

echo'5'.chr(10); 

   

/*

* we just got notified that there are symbols waiting

*/ 

foreach(array("sym","arr","obj","objs","res")as$symbol){ 

    printf("\$thread->%s: ",$symbol);    

    $fetched= $thread->$symbol

    if($fetched) { 

        switch($symbol){ 

            /*

            * manual unserialize

            */ 

            case"objs"

                var_dump(unserialize($fetched)); 

            break

               

            default: var_dump($fetched); 

        

    

    printf("\n"); 

   

/* notify the thread so it can destroy resource */ 

$thread->synchronized(function($me){ 

    $me->notify(); 

},$thread); 

?> 


在命令框输入:/usr/local/php-zts/bin/php Fetch.php



直接在网页没有输出,需要调用PHP脚本运行。


参照文章:

http://www.2cto.com/kf/201309/245093.html

http://blog.csdn.net/crz03128/article/details/25954441


编译了很久,做个记录。

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SecLists

SecLists

SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。