Swoole Learning Swoole Source Installation

Posted by PRSWeb on Thu, 03 Oct 2019 01:56:16 +0200

1. swoole source download

Swoole official website download: https://www.swoole.com/ We download it with the source code (open source China) library.

Here we use git to clone the source code package directly to the local

root@5ee6bfcc1310:/work/study/softpackage# git clone git@gitee.com:swoole/swoole.git

Or download it directly with curl and decompress the package:

curl https://gitee.com/swoole/swoole/repository/archive/master.zip

2. swoole Source Installation

The source code installation of swoole is basically the same as that of php, but swoole does not have a configuration installation file, which requires us to use phpize(phpize is used to add extension modules, which can build PHP plug-in modules) to generate such files.

Enter the swoole source package directory and execute the / work/study/soft/php/bin/phpize command:

swoole# /work/study/soft/php/bin/phpize
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718

When we look at the swoole source package, we generate multiple files, including the configuration file.

Compile:

swoole#  ./configure --with-php-config=/work/study/soft/php/bin/php-config
swoole# make && make install

--with means to specify the installed php version. If there are multiple php versions in the system, you need to specify

Compiled results:

...

PATH="$PATH:/sbin" ldconfig -n /work/study/softpackage/swoole/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /work/study/softpackage/swoole/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 `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

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:     /work/study/soft/php/lib/php/extensions/no-debug-non-zts-20170718/
Installing header files:          /work/study/soft/php/include/php/
root@5ee6bfcc1310:/work/study/softpackage/swoole#

The extensions are placed in the directory of / work/study/soft/php/lib/php/extensions/no-debug-non-zts-20170718/. Let's look at the directory:

root@5ee6bfcc1310:/work/study/soft/php/bin# cd /work/study/soft/php/lib/php/extensions/no-debug-non-zts-20170718/
root@5ee6bfcc1310:/work/study/soft/php/lib/php/extensions/no-debug-non-zts-20170718# ls -l
total 21820
-rwxr-xr-x 1 root root  5227454 Aug 27 18:07 opcache.a
-rwxr-xr-x 1 root root  2413144 Aug 27 18:07 opcache.so
-rwxr-xr-x 1 root root 14696248 Aug 28 11:06 swoole.so

The file swoole.so is our compiled extension file.

3. PHP supports Swoole

If PHP wants to use the extended class library, it must do some configuration in the php.ini file to use it, otherwise it will fail to find the file.

Edit php.ini file

root@5ee6bfcc1310:/work/study/soft/php/lib# vim php.ini

Add a new line to the extension:

extension=swoole

Check to see if there is a swoole extension:

root@5ee6bfcc1310:/work/study/soft/php/lib# php -m
[PHP Modules]
Core
ctype
date
dom
fileinfo
filter
hash
iconv
json
libxml
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
swoole
tokenizer
xml
xmlreader
xmlwriter

[Zend Modules]

We can see that the extension of PHP already has swoole, so far, our PHP and Swoole installation compiled.

Topics: PHP git curl Linker