function test($url){
$pid = pcntl_fork();
if( 0 == $pid ) {
$R = file_get_contents($url );
}
elseif( $pid > 0 ){
for( $i = 1; $i <= 50; $i++ ){
sleep( 1 );
// posix_getppid()函数的作用就是获取当前进程的父进程进程 ID
var_dump( memory_get_usage() );
}
pcntl_wait($status); //, WNOHANG
pcntl_waitpid(-1, $status); //, WNOHANG
} else {
echo "fork error.";
}
}
$url = 'http://23.252.96.201/100mb.bin';
test($url);
结果:
sh-4.2# php client.php
int(390248)
int(390280)
int(390280)
int(390280)
int(390280)
int(390280)
int(390280)
int(390280)
int(390280)
int(390280)
int(390280)
int(390280)
int(390280)
int(390280)
int(390280)
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 98566176 bytes) in /www/forgetword.yixuewenku.cn/client.php on line 223
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 98566176 bytes) in /www/forgetword.yixuewenku.cn/client.php on line 223
int(390280)
int(390280)
int(390280)
^Z
[5]+ Stopped(SIGTSTP) php client.php
sh-4.2#