?????????????????Linux?μ?PHP?????г??????????????????????????ж????????????TCPЭ?鷢?????????????????????????????????????????????????????????????????????????????????????????????????????????ж?????????

?????????????????PHP?????г????????????????????д???????д???????????????PHP????exec()??popen()?????????shell???????????????У????磺

<?php
exec("/bin/sh /opt/zhangyan.sh &");
?>

???????&?????shell????????????С?

??????????????????????????????????????????????·????????????????????????????????????????

--------------------------------------------------------------------------------

??????д?????PHP????/opt/zhangyan.php???????shell????/opt/zhangyan.sh???????????????

??????????????

????1??????/opt/zhangyan.php??????????500????????

????2????/opt/zhangyan.php?????????????????????????????????1?????н?????$p_number=500-1=499??????????????/opt/zhangyan.sh??????????????/opt/zhangyan.sh??????????????????????????

????3????????????????????????0??????н?????$p_number=0????/opt/zhangyan.php????1???????????????ж????/opt/zhangyan.sh???????δ?????????

????4?????1???????/opt/zhangyan.php????????/opt/zhangyan.sh???????????500?????н?????$p_number=0????????????1?????????????

????5?????/opt/zhangyan.php????????δ?????????/opt/zhangyan.sh????????????300????????н?????$p_number=500-300=200???????/opt/zhangyan.php?????????????200??/opt/zhangyan.sh??????

--------------------------------------------------------------------------------

????/opt/zhangyan.php???????£?

<?php
function run($input)
{
global $p_number;
if ($p_number <= 0)
{
$p_number = worker_processes($p_number);
}
$p_number = $p_number - 1;
$out = popen("/bin/sh /opt/zhangyan.sh "{$input}" &"?? "r");
pclose($out);
}
function worker_processes($p_number)
{
$limit = 500;//??????????????????
while ($p_number <= 0)
{
$cmd = popen("ps -ef | grep "/opt/zhangyan.sh" | grep -v grep | wc -l"?? "r");
$line = fread($cmd?? 512);
pclose($cmd);
$p_number = $limit - $line;
if ($p_number <= 0)
{
sleep(1);//???1????
}
}
return $p_number;
}
$input = http://blog.s135.com; //???????????ж??????????
for ($i = 1; $i <= 1000; $i++)
{
run($input);
echo "Idle process number: " . $p_number . " ";
}
?>

??????/opt/zhangyan.php???????????????????ж??1000????????????????/opt/zhangyan.sh????????