热搜:NVER node 开发 php

php循环请求多个url

2024-09-07 17:35:01
php循环请求多个url

向当前网段(192.168.1.0~192.168.1.255),请求url,发送数据。
要求循环执行url,不需要对返回的结果进行处理,不等待返回结果。
请问功能该如何实现?。


回复讨论(解决方案)

<?phpfor ($index = 1; $index <= 255; $index ++ ) {    @fclose(fsockopen("192.168.1.$index", 80, $errno, $errstr, 0));}?>

PHP code?1234567<?php for ($index = 1; $index <= 255; $index ++ ) { @fclose(fsockopen("192.168.1.$index", 80, $errno, $errstr, 0));} ?>
谢谢回复。 socket只是打开链接。 并没有执行这个url吧? 请问该如何执行这个url呢?

$streamData	 = "GET {$url} HTTP/1.0\r\n";		$streamData	.= "Accept: */*\r\n";		$streamData	.= "Accept-Language: zh-cn\r\n";				$streamData	.= "Host: {$host}\r\n";		$streamData	.= "Connection: Close\r\n";		$streamData .= "Cookie:  \r\n\r\n";   						$ip = "";		$timeout= 15;		$fp	= fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);					$ret= "";		if(!$fp)		{   			return '$errstr : $errno';//note $errstr : $errno \r\n   		} 		else 		{   			//集阻塞/非阻塞模式流,$block==true则应用流模式			stream_set_blocking($fp, false);			//设置流的超时时间   			//stream_set_timeout($fp, $timeout);			fputs($fp, $streamData);			//while (!feof($fp)) {			//$ret	.= fgets($fp, 128);			//}			fclose($fp);			//echo $ret;			}

fopen("http://127.0.0.1:8182/now/form.php?id=5689","r");
file_get_contents("http://127.0.0.1:8182/now/form.php?id=5689");
运行指定url,两种方法在apache上运行都是成功的。
在ngiux中却失败了。 请教原因

要让文件函数作用于 url 需要 php.ini
allow_url_fopen = On

allow_url_fopen = On //已经开启

test.php
<?php
  echo  file_get_contents("http://localhost:8182/now/form.php");
?>
form.php
<?php
echo "abc";
?>
-------------------------
相同代码在apache和nginx执行是不同的效果。
运行test.php:
    apache输出结果为:abc; nginx运行出错,页面一直处于刷新状态

要让文件函数作用于 url 需要 php.ini
allow_url_fopen = On 相同代码在apache和nginx执行是不同的效果.请帮忙分析下原因。 谢谢

可能是 nginx 配置问题吧?不清楚