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

解决方案 »

  1.   

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

  2.   

    谢谢回复。 socket只是打开链接。 并没有执行这个url吧? 请问该如何执行这个url呢?
      

  3.   

    $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;
    }
      

  4.   

    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中却失败了。 请教原因
      

  5.   

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

  6.   

    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运行出错,页面一直处于刷新状态
      

  7.   

    相同代码在apache和nginx执行是不同的效果.请帮忙分析下原因。 谢谢
      

  8.   

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