Giter VIP home page Giter VIP logo

phpgo's Introduction

996.icu LICENSE

phpgo

phpgo's mission is to provide a small, simple, stable extension for existing and future PHP applications for much higher concurrency, better performance, with lower resouce consumption and work well with most of the existing php features, extensions and frameworks

phpgo: A php extension that brings into php the go core features:

  • go routine
  • channel
  • select
  • mutex
  • waitgroup
  • timer
  • go routine scheduler

phpgo also brings in a break-through feature which:

  • automatically converts the synchronized function calls in the php extensions (e.g. PDO, redis... etc) into asynchronized

This allows the swithing of execution to another go routine if one go routine is blocked by blocking I/O, thus provides hundred to thousand times of concurrent executions under the same running environment

phpgo can be used under both CLI mode and fast-cgi (php-fpm) mode

phpgo supports php5.4 to 7.2 on linux as of today

0. Reference Manuals

1. Getting started

1.1. Install libgo

The phpgo relies on the the libgo library (thanks libgo!) to provide the underlying coroutine capability, which includes:

  • coroutine creation, execution and scheduling
  • coroutine local storage
  • coroutine listener with the task swap hook capability
  • go channel
  • go mutex
  • hook of system calls (thus allow corroutine switching during blocking system call)

(libgo contains more excellent features and you may want to check them out @ https://github.com/yyzybb537/libgo )

steps to install the libgo:

git clone https://github.com/yyzybb537/libgo
cd libgo
git checkout master
git pull
git reset --hard c280e6170a7d7bd124d98a8062cb47989f9ae4cd   #use a compatible version of libgo
mkdir build
cd build
rm -rf *
cmake ..
make
make install
ldconfig

1.2. Build phpgo from source - supported on linux OS

steps to build phpgo:

git clone https://github.com/birdwyx/phpgo
cd phpgo
phpize
./configure -with-php-config=<the path to php-config>
make
make install

you may probably want to do a test first to ensure everything is fine before start using phpgo

cd phpgo
export TEST_PHP_EXECUTABLE=./test_php
php run-tests.php tests

ensure there are no FAIL'ed test cases

then, add the following line into the php.ini

extension=phpgo.so

1.3. First phpgo program

hello_world.php:

<?php
use \go\Scheduler; //for the Scheduler functions 

go(function(){   //creates a go routine
    echo "Hello World!" . PHP_EOL;
});

Scheduler::join();  //execute all go routines

run this program under the command line:

#php hello_world.php
Hello World!
#

Have fun!

1.4. Using phpgo under fast-cgi mode

phpgo can be used under fast-cgi (php-fpm) mode, following are the steps:

Make libgo preloaded

You need to modify your php-fpm service management script (/etc/init.d/php-fpm), add the following line to the /etc/init.d/php-fpm at the very begining of the "start)" section:

export LD_PRELOAD=liblibgo.so

after your modification, the file should look like the following:

/etc/init.d/php-fpm:
...
case "$1" in
    start)
        echo -n "Starting php-fpm - with libgo preloaded"
        export LD_PRELOAD=liblibgo.so
        $php_fpm_BIN --daemonize $php_opts
        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        fi
...

then issue a "service php-fpm reload" to make the modification take effect

#service php-fpm reload

The reason to do that is for you to obtain the capability that allows the swithing of execution to another go routine while a go routine is I/O blocked, the LD_PRELOAD=liblibgo.so does the trick. For more information, see the dedicated section below that describes the details of what libgo has done for this capability, why the LD_PRELOAD is needed and how it functions.

Setup your go scheduler

A typical way to setup the go scheduler is to add the Scheduler::join() into the index.php

index.php:
use \go\Scheduler
...
your existing code which typically boots up a framework(e.g, laravel) 
who in turns runs your web service
...

Scheduler::join(); // the last line

Feel free to use the phpgo capability in your web service code

The places that you most likely to use the phpgo functions/methods are the Models / Controllers. The following code demonstrates a uses case where an API gateway consolidate a user's basic information, order placed, and browsing history and send back to the web broswer:

use \go\Scheduler;
...
function getUserDetailInfo(){
    $userid = $_GET['userid']; 
    $user_details = [];
    $user_orders = [];
    $user_browsing_history = [];
    
    go(function(&$user_details){
        $redis = new Redis();
        $redis->connect(...);
        $user_details = $redis->get( "user_details_of_" . $userid );
    }, [&$user_details]);
    
    go(function(&$user_orders){
        $pdo = new PDO(...);
        $user_orders = $pdo->query("select * from tb_order where userid = $userid");
    }, [&$user_orders]);
    
    go(function(&$user_browsing_history){
        $curl = new Curl(...);
        $user_browsing_history =
            $curl->get("http://browsing.history.micro.service/path_to_the_browsing_history_query_api");
    }, [&$user_browsing_history]);
    
    Scheduler::join();
    
    $result = array(
        'user_details' = > $user_details,
        'user_orders' => $user_orders,
        'user_browsing_history' => $user_browsing_history,
    );
    
    echo json_encode($result);
}
...

The code above creates 3 go routines, which run in parallel getting the user basic information, order information and browsing history from redis, databases, and a microservice running http interface; the Scheduler::join() schedules and wait all the 3 go routines to finish running; then the code send back the consolidated result to the broswer

As we all know, due to the synchronized nature of php, in a php script all operations have to be exectued in sequence, in an API gateway that has a lot of interactions with other conter-parts, the total amount of execution time of a script can easily become unacceptable. By using phpgo, the amount of total execution time can reduce to the time of a single operation(given the operations are independent and can be executed in parallel)

2. LD_PRELOAD

to be updated...

3. Go Live

libgo supports using boost context for context switching (default context switching mechanism is u_context) which provides a much better coroutine switch performance (5+ times).

If you are using the phpgo under production environment, it's recommended that you enable the boost context switching by the steps below:

Firstly, you'll need to install boost 1.59.0+, I'll suggest you use 1.59.0, since libgo is using 1.59.0 in auto-integeration testing (as of today: 2018/5/25)

#wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
#tar -xvf boost_1_59_0.tar.gz
#cd boost_1_59_0
#./bootstrap.sh
#./b2 -q install

Then, you'll need to add -DENABLE_BOOST_CONTEXT=ON option to the "cmake" command

#cd libgo/build
#rm -rf *
#cmake .. -DENABLE_BOOST_CONTEXT=ON
#make && make install

note: if you see compiler errors during the "make" step, make sure you've done the "rm -rf * " under the build directory

phpgo's People

Contributors

birdwyx avatar helloworld2050 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpgo's Issues

go函数内使用sleep居然是挨个跳出来,不能利用多核吗?

<?php
use \go\Scheduler; //for the Scheduler functions 

go(function(){   //creates a go routine
    sleep(1);
    echo "Hello World!" . PHP_EOL;
});

go(function(){   //creates a go routine
    sleep(1);
    echo "Hello World!2" . PHP_EOL;
});


go(function(){   //creates a go routine
    sleep(1);
    echo "Hello World!3" . PHP_EOL;
});

go(function(){   //creates a go routine
    sleep(1);
    echo "Hello World!4" . PHP_EOL;
});

go(function(){   //creates a go routine
    sleep(1);
    echo "Hello World!5" . PHP_EOL;
});

Scheduler::join();  //execute all go routines

PHP-7.2 下编译失败

  • php-7.2
  • gcc 5.4.0
  • ubuntu 16.04
make
/bin/bash /home/htf/workspace/c/phpgo/libtool --mode=compile g++  -I. -I/home/htf/workspace/c/phpgo -DPHP_ATOM_INC -I/home/htf/workspace/c/phpgo/include -I/home/htf/workspace/c/phpgo/main -I/home/htf/workspace/c/phpgo -I/opt/php/php-7.2/include/php -I/opt/php/php-7.2/include/php/main -I/opt/php/php-7.2/include/php/TSRM -I/opt/php/php-7.2/include/php/Zend -I/opt/php/php-7.2/include/php/ext -I/opt/php/php-7.2/include/php/ext/date/lib  -DHAVE_CONFIG_H  -std=c++11 -g -O0   -c /home/htf/workspace/c/phpgo/src/zend_variables_persist.cc -o src/zend_variables_persist.lo 
 g++ -I. -I/home/htf/workspace/c/phpgo -DPHP_ATOM_INC -I/home/htf/workspace/c/phpgo/include -I/home/htf/workspace/c/phpgo/main -I/home/htf/workspace/c/phpgo -I/opt/php/php-7.2/include/php -I/opt/php/php-7.2/include/php/main -I/opt/php/php-7.2/include/php/TSRM -I/opt/php/php-7.2/include/php/Zend -I/opt/php/php-7.2/include/php/ext -I/opt/php/php-7.2/include/php/ext/date/lib -DHAVE_CONFIG_H -std=c++11 -g -O0 -c /home/htf/workspace/c/phpgo/src/zend_variables_persist.cc  -fPIC -DPIC -o src/.libs/zend_variables_persist.o
In file included from /opt/php/php-7.2/include/php/Zend/zend.h:33:0,
                 from /opt/php/php-7.2/include/php/main/php.h:35,
                 from /home/htf/workspace/c/phpgo/src/stdinc.h:8,
                 from /home/htf/workspace/c/phpgo/src/zend_variables_persist.cc:21:
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc: In function ‘void _zval_persistent_copy_ctor_func(zval*, const char*, uint32_t)’:
/opt/php/php-7.2/include/php/Zend/zend_string.h:51:33: error: ‘zval {aka struct _zval_struct}’ has no member named ‘val’
 #define ZSTR_VAL(zstr)  (zstr)->val
                                 ^
/opt/php/php-7.2/include/php/Zend/zend_API.h:583:6: note: in expansion of macro ‘ZSTR_VAL’
  if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", ZSTR_VAL(str) ZEND_FILE_LINE_RELAY_CC); }
      ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc:110:4: note: in expansion of macro ‘CHECK_ZVAL_STRING_REL’
    CHECK_ZVAL_STRING_REL(zvalue);
    ^
/opt/php/php-7.2/include/php/Zend/zend_string.h:52:33: error: ‘zval {aka struct _zval_struct}’ has no member named ‘len’
 #define ZSTR_LEN(zstr)  (zstr)->len
                                 ^
/opt/php/php-7.2/include/php/Zend/zend_API.h:583:20: note: in expansion of macro ‘ZSTR_LEN’
  if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", ZSTR_VAL(str) ZEND_FILE_LINE_RELAY_CC); }
                    ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc:110:4: note: in expansion of macro ‘CHECK_ZVAL_STRING_REL’
    CHECK_ZVAL_STRING_REL(zvalue);
    ^
/opt/php/php-7.2/include/php/Zend/zend_string.h:51:33: error: ‘zval {aka struct _zval_struct}’ has no member named ‘val’
 #define ZSTR_VAL(zstr)  (zstr)->val
                                 ^
/opt/php/php-7.2/include/php/Zend/zend_API.h:583:122: note: in expansion of macro ‘ZSTR_VAL’
  if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", ZSTR_VAL(str) ZEND_FILE_LINE_RELAY_CC); }
                                                                                                                          ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc:110:4: note: in expansion of macro ‘CHECK_ZVAL_STRING_REL’
    CHECK_ZVAL_STRING_REL(zvalue);
    ^
/opt/php/php-7.2/include/php/Zend/zend_string.h:51:33: error: ‘zval {aka struct _zval_struct}’ has no member named ‘val’
 #define ZSTR_VAL(zstr)  (zstr)->val
                                 ^
/opt/php/php-7.2/include/php/Zend/zend_API.h:583:6: note: in expansion of macro ‘ZSTR_VAL’
  if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", ZSTR_VAL(str) ZEND_FILE_LINE_RELAY_CC); }
      ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc:121:4: note: in expansion of macro ‘CHECK_ZVAL_STRING_REL’
    CHECK_ZVAL_STRING_REL(zvalue);
    ^
/opt/php/php-7.2/include/php/Zend/zend_string.h:52:33: error: ‘zval {aka struct _zval_struct}’ has no member named ‘len’
 #define ZSTR_LEN(zstr)  (zstr)->len
                                 ^
/opt/php/php-7.2/include/php/Zend/zend_API.h:583:20: note: in expansion of macro ‘ZSTR_LEN’
  if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", ZSTR_VAL(str) ZEND_FILE_LINE_RELAY_CC); }
                    ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc:121:4: note: in expansion of macro ‘CHECK_ZVAL_STRING_REL’
    CHECK_ZVAL_STRING_REL(zvalue);
    ^
/opt/php/php-7.2/include/php/Zend/zend_string.h:51:33: error: ‘zval {aka struct _zval_struct}’ has no member named ‘val’
 #define ZSTR_VAL(zstr)  (zstr)->val
                                 ^
/opt/php/php-7.2/include/php/Zend/zend_API.h:583:122: note: in expansion of macro ‘ZSTR_VAL’
  if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", ZSTR_VAL(str) ZEND_FILE_LINE_RELAY_CC); }
                                                                                                                          ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc:121:4: note: in expansion of macro ‘CHECK_ZVAL_STRING_REL’
    CHECK_ZVAL_STRING_REL(zvalue);
    ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc: In function ‘void _zval_persistent_to_local_copy_ctor_func(zval*, const char*, uint32_t)’:
/opt/php/php-7.2/include/php/Zend/zend_string.h:51:33: error: ‘zval {aka struct _zval_struct}’ has no member named ‘val’
 #define ZSTR_VAL(zstr)  (zstr)->val
                                 ^
/opt/php/php-7.2/include/php/Zend/zend_API.h:583:6: note: in expansion of macro ‘ZSTR_VAL’
  if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", ZSTR_VAL(str) ZEND_FILE_LINE_RELAY_CC); }
      ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc:234:4: note: in expansion of macro ‘CHECK_ZVAL_STRING_REL’
    CHECK_ZVAL_STRING_REL(zvalue);
    ^
/opt/php/php-7.2/include/php/Zend/zend_string.h:52:33: error: ‘zval {aka struct _zval_struct}’ has no member named ‘len’
 #define ZSTR_LEN(zstr)  (zstr)->len
                                 ^
/opt/php/php-7.2/include/php/Zend/zend_API.h:583:20: note: in expansion of macro ‘ZSTR_LEN’
  if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", ZSTR_VAL(str) ZEND_FILE_LINE_RELAY_CC); }
                    ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc:234:4: note: in expansion of macro ‘CHECK_ZVAL_STRING_REL’
    CHECK_ZVAL_STRING_REL(zvalue);
    ^
/opt/php/php-7.2/include/php/Zend/zend_string.h:51:33: error: ‘zval {aka struct _zval_struct}’ has no member named ‘val’
 #define ZSTR_VAL(zstr)  (zstr)->val
                                 ^
/opt/php/php-7.2/include/php/Zend/zend_API.h:583:122: note: in expansion of macro ‘ZSTR_VAL’
  if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", ZSTR_VAL(str) ZEND_FILE_LINE_RELAY_CC); }
                                                                                                                          ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc:234:4: note: in expansion of macro ‘CHECK_ZVAL_STRING_REL’
    CHECK_ZVAL_STRING_REL(zvalue);
    ^
/opt/php/php-7.2/include/php/Zend/zend_string.h:51:33: error: ‘zval {aka struct _zval_struct}’ has no member named ‘val’
 #define ZSTR_VAL(zstr)  (zstr)->val
                                 ^
/opt/php/php-7.2/include/php/Zend/zend_API.h:583:6: note: in expansion of macro ‘ZSTR_VAL’
  if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", ZSTR_VAL(str) ZEND_FILE_LINE_RELAY_CC); }
      ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc:245:4: note: in expansion of macro ‘CHECK_ZVAL_STRING_REL’
    CHECK_ZVAL_STRING_REL(zvalue);
    ^
/opt/php/php-7.2/include/php/Zend/zend_string.h:52:33: error: ‘zval {aka struct _zval_struct}’ has no member named ‘len’
 #define ZSTR_LEN(zstr)  (zstr)->len
                                 ^
/opt/php/php-7.2/include/php/Zend/zend_API.h:583:20: note: in expansion of macro ‘ZSTR_LEN’
  if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", ZSTR_VAL(str) ZEND_FILE_LINE_RELAY_CC); }
                    ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc:245:4: note: in expansion of macro ‘CHECK_ZVAL_STRING_REL’
    CHECK_ZVAL_STRING_REL(zvalue);
    ^
/opt/php/php-7.2/include/php/Zend/zend_string.h:51:33: error: ‘zval {aka struct _zval_struct}’ has no member named ‘val’
 #define ZSTR_VAL(zstr)  (zstr)->val
                                 ^
/opt/php/php-7.2/include/php/Zend/zend_API.h:583:122: note: in expansion of macro ‘ZSTR_VAL’
  if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", ZSTR_VAL(str) ZEND_FILE_LINE_RELAY_CC); }
                                                                                                                          ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc:245:4: note: in expansion of macro ‘CHECK_ZVAL_STRING_REL’
    CHECK_ZVAL_STRING_REL(zvalue);
    ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc: In function ‘void _zval_persistent_dtor_func(zval*, const char*, uint32_t)’:
/opt/php/php-7.2/include/php/Zend/zend_string.h:51:33: error: ‘zval {aka struct _zval_struct}’ has no member named ‘val’
 #define ZSTR_VAL(zstr)  (zstr)->val
                                 ^
/opt/php/php-7.2/include/php/Zend/zend_API.h:583:6: note: in expansion of macro ‘ZSTR_VAL’
  if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", ZSTR_VAL(str) ZEND_FILE_LINE_RELAY_CC); }
      ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc:344:4: note: in expansion of macro ‘CHECK_ZVAL_STRING_REL’
    CHECK_ZVAL_STRING_REL(zvalue);
    ^
/opt/php/php-7.2/include/php/Zend/zend_string.h:52:33: error: ‘zval {aka struct _zval_struct}’ has no member named ‘len’
 #define ZSTR_LEN(zstr)  (zstr)->len
                                 ^
/opt/php/php-7.2/include/php/Zend/zend_API.h:583:20: note: in expansion of macro ‘ZSTR_LEN’
  if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", ZSTR_VAL(str) ZEND_FILE_LINE_RELAY_CC); }
                    ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc:344:4: note: in expansion of macro ‘CHECK_ZVAL_STRING_REL’
    CHECK_ZVAL_STRING_REL(zvalue);
    ^
/opt/php/php-7.2/include/php/Zend/zend_string.h:51:33: error: ‘zval {aka struct _zval_struct}’ has no member named ‘val’
 #define ZSTR_VAL(zstr)  (zstr)->val
                                 ^
/opt/php/php-7.2/include/php/Zend/zend_API.h:583:122: note: in expansion of macro ‘ZSTR_VAL’
  if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", ZSTR_VAL(str) ZEND_FILE_LINE_RELAY_CC); }
                                                                                                                          ^
/home/htf/workspace/c/phpgo/src/zend_variables_persist.cc:344:4: note: in expansion of macro ‘CHECK_ZVAL_STRING_REL’
    CHECK_ZVAL_STRING_REL(zvalue);
    ^
Makefile:206: recipe for target 'src/zend_variables_persist.lo' failed
make: *** [src/zend_variables_persist.lo] Error 1

启用 Syscall Hook 调用 PDO 无效

代码

<?php
use \Go\Chan;
use \Go\Scheduler;

go(function () {
	$user='root';
	$pass='root';
	$dsn="mysql:host=127.0.0.1;dbname=test";
	$db = new PDO($dsn, $user, $pass);
	$rs = $db->query("show tables");
	var_dump($rs->fetchall());
});

Scheduler::join();

执行

htf@htf-All-Series:~/workspace/cpp/phpgo$ LD_PRELOAD=liblibgo.so php t.php 

没有任何输出

关闭SysCall Hook 直接使用同步阻塞IOPDO可以正确返回数据。

htf@htf-All-Series:~/workspace/cpp/phpgo$ php t.php 
array(2) {
  [0]=>
  array(2) {
    ["Tables_in_test"]=>
    string(3) "ckl"
    [0]=>
    string(3) "ckl"
  }
  [1]=>
  array(2) {
    ["Tables_in_test"]=>
    string(8) "userinfo"
    [0]=>
    string(8) "userinfo"
  }
}

strace

htf@htf-All-Series:~/workspace/cpp/phpgo$ LD_PRELOAD=liblibgo.so strace php t.php 
execve("/home/htf/bin/php", ["php", "t.php"], [/* 71 vars */]) = 0
brk(NULL)                               = 0x2f8d000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/usr/local/lib/tls/x86_64/liblibgo.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/local/lib/tls/x86_64", 0x7fff97863760) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/tls/liblibgo.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/local/lib/tls", 0x7fff97863760) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/x86_64/liblibgo.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/local/lib/x86_64", 0x7fff97863760) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/liblibgo.so", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320\373\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=3402616, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd438555000
mmap(NULL, 2428848, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fd4380e0000

....


socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 5
fcntl(5, F_GETFL)                       = 0x2 (flags O_RDWR)
fstat(5, {st_mode=S_IFSOCK|0777, st_size=0, ...}) = 0
fcntl(5, F_GETFL)                       = 0x2 (flags O_RDWR)
fcntl(5, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
getsockopt(5, SOL_SOCKET, SO_TYPE, [1], [4]) = 0
fcntl(5, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
connect(5, {sa_family=AF_INET, sin_port=htons(3306), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress)
poll([{fd=5, events=POLLIN|POLLOUT|POLLERR|POLLHUP}], 1, 0) = 1 ([{fd=5, revents=POLLOUT}])
getsockopt(5, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
fcntl(5, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
setsockopt(5, SOL_TCP, TCP_NODELAY, [1], 4) = 0
setsockopt(5, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
poll([{fd=5, events=POLLIN|POLLERR|POLLHUP}], 1, 0) = 1 ([{fd=5, revents=POLLIN}])
epoll_create(10240)                     = 6
rt_sigaction(SIGPIPE, {SIG_IGN, [], SA_RESTORER, 0x7fd4355f24b0}, NULL, 8) = 0
epoll_ctl(6, EPOLL_CTL_ADD, 5, {EPOLLIN, {u32=5, u64=4294967301}}) = 0
rt_sigprocmask(SIG_SETMASK, [], [], 8)  = 0
epoll_wait(6, [{EPOLLIN, {u32=5, u64=4294967301}}], 1024, 0) = 1
epoll_ctl(6, EPOLL_CTL_DEL, 5, 0x7fff97860cc8) = 0
epoll_wait(6, [], 1024, 20)             = 0
epoll_wait(6, [], 1024, 20)             = 0
epoll_wait(6, [], 1024, 20)             = 0
epoll_wait(6, [], 1024, 20)             = 0


  • open("/usr/local/lib/liblibgo.so", O_RDONLY|O_CLOEXEC) = 3 说明正确加载了 libgo.so
  • socket connect 3306 也是对的,但epoll_wait后直接调用EPOLL_CTL_DEL删除了socket

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.