php安裝pcntl擴充套件
參考:http://www.cnblogs.com/yjf512/p/3217615.html
還是老三樣:phpize, ./configure, make && make install
當然是要到你下載的php原始碼的ext目錄中執行。
[email protected]:~/Downloads/php-5.4.30/ext/pcntl$ phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
[email protected]:~/Downloads/php-5.4.30/ext/pcntl$ ./configure
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... i386-apple-darwin13.4.0
checking host system type... i386-apple-darwin13.4.0
checking target system type... i386-apple-darwin13.4.0
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib
checking for PHP extension directory... /usr/lib/php/extensions/no-debug-non-zts-20100525
checking for PHP installed headers prefix... /usr/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking whether to enable pcntl support... yes, shared
checking for fork... yes
checking for waitpid... yes
checking for sigaction... yes
checking for getpriority... yes
checking for setpriority... yes
checking for wait3... yes
checking for sigprocmask... yes
checking for sigwaitinfo... no
checking for sigtimedwait... no
checking for ld used by cc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
checking if the linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 196608
checking command to parse /usr/bin/nm output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking if cc supports -fno-rtti -fno-exceptions... yes
checking for cc option to produce PIC... -fno-common
checking if cc PIC flag -fno-common works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin13.4.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged
[email protected]:~/Downloads/php-5.4.30/ext/pcntl$ make && make install
/bin/sh /Users/andy/Downloads/php-5.4.30/ext/pcntl/libtool --mode=install cp ./pcntl.la /Users/andy/Downloads/php-5.4.30/ext/pcntl/modules
cp ./.libs/pcntl.so /Users/andy/Downloads/php-5.4.30/ext/pcntl/modules/pcntl.so
cp ./.libs/pcntl.lai /Users/andy/Downloads/php-5.4.30/ext/pcntl/modules/pcntl.la
----------------------------------------------------------------------
Libraries have been installed in:
/Users/andy/Downloads/php-5.4.30/ext/pcntl/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
during execution
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20100525/
cp: /usr/lib/php/extensions/no-debug-non-zts-20100525/#[email protected]#: Permission denied
make: *** [install-modules] Error 1
[email protected]:~/Downloads/php-5.4.30/ext/pcntl$ php -m
[PHP Modules]
andy
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gd
hash
iconv
json
ldap
libxml
mbstring
mssql
mysql
mysqli
mysqlnd
openssl
pcre
PDO
pdo_dblib
pdo_mysql
PDO_ODBC
pdo_sqlite
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
snmp
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
wddx
xdebug
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib
[Zend Modules]
Xdebug
[email protected]:~/Downloads/php-5.4.30/ext/pcntl$ vim /private/etc/php.ini
[email protected]:~/Downloads/php-5.4.30/ext/pcntl$ sudo vim /private/etc/php.ini
Password:
[email protected]:~/Downloads/php-5.4.30/ext/pcntl$ php -m
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20100525/pcntl' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20100525/pcntl, 9): image not found in Unknown on line 0
[PHP Modules]
andy
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gd
hash
iconv
json
ldap
libxml
mbstring
mssql
mysql
mysqli
mysqlnd
openssl
pcre
PDO
pdo_dblib
pdo_mysql
PDO_ODBC
pdo_sqlite
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
snmp
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
wddx
xdebug
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib
[Zend Modules]
Xdebug
我們看到擴充套件了還是沒有pcntl擴充套件,可以看到上面有一個cp的error,所以我們sudo一下:
[email protected]:~/Downloads/php-5.4.30/ext/pcntl$ sudo make
/bin/sh /Users/andy/Downloads/php-5.4.30/ext/pcntl/libtool --mode=install cp ./pcntl.la /Users/andy/Downloads/php-5.4.30/ext/pcntl/modules
cp ./.libs/pcntl.so /Users/andy/Downloads/php-5.4.30/ext/pcntl/modules/pcntl.so
cp ./.libs/pcntl.lai /Users/andy/Downloads/php-5.4.30/ext/pcntl/modules/pcntl.la
----------------------------------------------------------------------
Libraries have been installed in:
/Users/andy/Downloads/php-5.4.30/ext/pcntl/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
during execution
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
[email protected]:~/Downloads/php-5.4.30/ext/pcntl$ sudo make install
Installing shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20100525/
[email protected]:/usr/lib/php/extensions/no-debug-non-zts-20100525$ php -m
[PHP Modules]
andy
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gd
hash
iconv
json
ldap
libxml
mbstring
mssql
mysql
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_dblib
pdo_mysql
PDO_ODBC
pdo_sqlite
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
snmp
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
wddx
xdebug
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib
[Zend Modules]
Xdebug
[email protected]:/usr/lib/php/extensions/no-debug-non-zts-20100525$
好了。
下面可以寫個示例試試:
for($x = 1;$x<= 2;$x++){
$pid[$x] = pcntl_fork();
if ($pid[$x] == -1) {
die("could not fork");
} elseif ($pid[$x]) {
echo "Parent: create ".$pid[$x]."n";
} else {
echo "fork ".getmypid()." start:n";
for($i = 0;$i<10;$i++){
echo $x.": ".$i."n";
sleep(1);
}
exit;
}
}
輸出結果是這樣的:
[email protected]:/usr/local/webdata/andy/php/pcntl$ php pcntl_demo.php
Parent: create 3641
Parent: create 3642
fork 3641 start:
1: 0
fork 3642 start:
2: 0
[email protected]:/usr/local/webdata/andy/php/pcntl$ 1: 1
2: 1
1: 2
2: 2
1: 3
2: 3
1: 4
2: 4
2: 5
1: 5
1: 6
2: 6
1: 7
2: 7
1: 8
2: 8
1: 9
2: 9
[email protected]:/usr/local/webdata/andy/php/pcntl$
這個時候我們去ps -ef|grep php的話,可以看到有兩個php程序:
如果我們改一下程式碼,加上19行後面的程式碼:
<?php
for($x = 1;$x<= 2;$x++){
$pid[$x] = pcntl_fork();
if ($pid[$x] == -1) {
die("could not fork");
} elseif ($pid[$x]) {
echo "Parent: create ".$pid[$x]."\n";
} else {
echo "fork ".getmypid()." start:\n";
for($i = 0;$i<10;$i++){
echo $x.": ".$i."\n";
sleep(1);
}
exit;
}
}
while(count($pid) > 0){
$myId = pcntl_waitpid(-1, $status, WNOHANG);
foreach($pid as $k => $v){
if($myId == $v) unset($pid[$k]);
}
usleep(100);
}
?>
可能有人會問WNOHANG是什麼意思,W NO HANG,也就是wait no hang,不阻塞的意思。
這個時候我們再執行,可以看到有三個php程序,最後一個php程序其實就是最開始的主程序,本來如果沒有加上的後面這段,主程序例項化出來兩個子程序之後就退出了,但是加上了這段,就會讓主程序等待所有子程序都結束之後,再結束自己。
相關推薦
php安裝pcntl擴充套件
參考:http://www.cnblogs.com/yjf512/p/3217615.html 還是老三樣:phpize, ./configure, make && make install 當然是要到你下載的php原始碼的ext目錄中執行。 [e
MACOSX下PHP安裝pdo_oci擴充套件
環境安裝 首先先去oracle官網下載Clinet SDK 下載地址 選擇下載 Basic、SDK這兩個檔案就行了。解壓後把倆個資料夾的內容合併 mv ~/Downloads/instantclient-basic-macos.x64-12.2.0.1.0-2/* ~/instan
Centos下PHP安裝Kafka擴充套件操作教程
說明:網上有好幾種PHP操作kafka的擴充套件,有kafka-php和php-rdkafka兩種是比較流行的。但其中kafka-php功能較全,但是使用composer安裝,對於內網使用者不能訪問外網,因此,我們選擇php-rdkafka。 php-rdkafka依賴librdkafka,先下
redis慢查詢日誌、php安裝redis擴充套件、redis儲存session、redis主從配置
一:redis慢查詢日誌 編輯配置檔案/etc/redis.conf針對慢查詢日誌,可以設定兩個引數,一個是執行時長,單位是微秒,另一個是慢查詢日誌的長度。當一個新的命令被寫入日誌時,最老的一條會從命令日誌佇列中被移除。 slowlog-log-slower-than 1000 //單位ms,表示慢於100
redis慢查詢日誌,php安裝redis擴充套件,redis儲存session,redis主從配置
redis慢查詢日誌 和mysql一樣redis也有慢查詢日誌,redis的慢查詢日誌預設是開啟的。針對慢查詢日誌,主要是設定兩個引數,一個是執行時長,單位是微秒,另一個是慢查詢日誌的長度。當一個新的命令被寫入日誌時,最老的一條會從命令日誌佇列中被移除。 編輯配置檔案,檔案中搜素slowlog,可以設
centos7 php安裝redis擴充套件
原始碼地址:https://github.com/phpredis/phpredis/releases 下載對應的版本wget https://github.com/phpredis/phpredis/archive/4.2.0RC2.zip 解壓:unzip 4.2.0RC2.zip
windows 下php安裝redis擴充套件
下載網站連結https://pecl.php.net/package/redis 1.下載php_redis.dll,下載地址https://pecl.php.net/package/redis 2.找到php安裝目錄將下載的包裡面的這兩個檔案放到ext資料夾裡 php_redis.dll
php 安裝Redis 擴充套件
1、用phpinfo();檢視php 的資訊 主要看 Architecture PHP Extension Build (ts vc 等要對應上) 2、https://windows.php.net/downloads/pecl/releases/igbinar
記錄一個PHP安裝redis擴充套件時的問題
安裝過程:https://www.cnblogs.com/pengyunjing/p/8688320.html 由於我之前安裝過該擴充套件,重新安裝時沒有執行make clean命令,所以安裝好出現了下面的錯誤: PHP Warning: PHP Startup: Unable to load
linux環境php安裝solr擴充套件(親測總結)
1、從http://pecl.php.net/package/solr下載最新版本。 我下載到/usr/tmp cd /usr/tmp wget https://pecl.php.net/get/solr-2.4.0.tgz
編譯安裝的php 安裝pdo_mysql擴充套件
1.進入擴充套件目錄 如果還未下載: a. 下載 檔案 wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz b. 解壓檔案 tar zxvf PDO_MYSQL-1.0.2.tgz cd PDO_MYSQL
centos7+php7.1.1安裝pcntl擴充套件
*擴充套件說明* pcntl 介紹 pcntl擴充套件可以支援 PHP 的多執行緒操作(僅限linux) phpize 介紹 phpize 可以用來給 PHP 動態的新增擴充套件。比如編譯 PHP 時忘記新增某擴充套件,後來想新增該擴充套件,即可以使用 phpize 動態的新增該擴
Linux php安裝fileinfo擴充套件
1.首先,找到擴充套件安裝的位置 find / -name fileinfo 2.cd 到該位置(根據自己的具體情況來) cd /usr/local/src/php7/ext/fileinfo/ 3.不要離開php安裝原始碼的ext/fileinfo目
windows系統 PHP安裝Redis擴充套件
首先在windows系統上安裝redis 1.下載地址https://github.com/dmajkic/redis/downloads。下載到的Redis支援32bit和64bit。根據自己實際情況選擇,我選擇32bit。把32bit檔案內容拷貝到需要安裝的目錄下,比如:D:\dev\redis-2
php安裝redis擴充套件,以及遇到的坑
先說問題吧 php 安裝redis擴充套件ext/standard/php_smart_str.h: No such file or directory 按照網上的教程安裝了redis的擴充套件,執行到 編譯安裝 make && make ins
Linux下php安裝Redis擴充套件(其他擴充套件同理)
1、cd /usr/local/src/ 切換到 3、tar zxvf 2.2.4.tar.gz 解壓檔案 4、cd phpredis-2.2.4 #進入安裝目錄 5 、/usr/local/php/bin/phpize # 使用 php
cmd安裝memcached 以及php安裝memcache擴充套件
1、下載memcached軟體 32位下載地址: memcached-win32-1.4.4-14.zip(直接下載),memcached-win32-1.4.4-14.zip下載頁面:http://blog.couchbase.com/memcached-144-windows-32-bit-
linux安裝mongodb及php安裝mongodb擴充套件
2.將mongodb的安裝包上傳至伺服器 使用 rz mongodb.tar 3.將壓縮包解壓到 /usr/local/mongodb tar -zxvf mongodb.tar mv mongodb /usr/local/ 4.
Linux上安裝Redis+PHP安裝Redis擴充套件
1.下載 下載地址:wget http://download.redis.io/releases/redis-4.0.8.tar.gz [[email protected]]#wget http://download.redis.io/releases/redi