服务器信息:
我目前正在尝试使用Perl并行启动1000个PHP CLI进程。然而,对于等效的Perl脚本,这需要 9.9秒vs 2.3秒。当我使用Perl脚本/opt/test.pl
进行测试时,所有1000个进程并行启动(ps -eLf | grep -ic 'test.pl'
)。当我使用/opt/testphp.php
进行测试时,使用ps -eLf | grep -ic 'testphp.php'
,我看到计数为250,然后它上升到580然后下降到0(脚本执行1000次,而不是并行)。 / p>
如果我遗漏了有助于确定问题的任何内容,请告诉我。
由于
Perl启动器脚本:
use Time::HiRes qw/ time sleep /;
my $command = '';
my $start = time;
my $filename = '/tmp/report.txt';
# open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
for $i(1 .. 1000) {
# $command = $command . "(perl /opt/test.pl &);"; // takes 2.3 seconds
$command = $command . "(php -q /opt/testphp.php &);"; // takes 9.9 seconds
}
system($command);
my $end = time;
print 'Total time taken: ', ( $end - $start ) , "\n";
PHP文件(testphp.php):
sleep(5);
$time = microtime(true);
file_put_contents('/tmp/report_20140804_php.log', "This is the record: $time\n", FILE_APPEND);
Perl文件(test.pl):
#! /usr/bin/perl
use Time::HiRes qw/ time sleep /;
sleep(5);
my $command = '';
my $start = time;
my $filename = '/tmp/report_20140804.log';
open(my $fh, '>>', $filename) or die "Could not open file '$filename' $!";
print $fh "Successfully saved entry $start\n";
close $fh;