I am totally new to php coding and also fsockopen command.

Through Telnet i am able to access my host at 192.168.0.150 10001(port)

Now i need to access the device(same host) through php fsockopen. i need to store the output to a variable and want to apply some calculation on that variable.

below is the coding i am using and error i am getting

<?php
$fp = fsockopen("192.168.0.150", 10001, $errno, $errstr, 10);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: 192.168.0.150\r\n";
$out .= "Connection: Close\r\n\r\n";
echo $out;
echo $fp;
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>

when i open this php file in my xampp local server i am getting below error.

Error message in browser
GET / HTTP/1.1 Host: 192.168.0.150 Connection: Close Resource id #22.60 2.59 2.60 2.59 2.60 2.60 2.60 2.60 2.60 2.59 2.60 2.60 2.60 2.59 2.60 2.60 2.60 2.60 2.60 2.59 2.60 2.59 2.59 2.59 2.59 2.60 2.60 2.60 2.59 2.60 2.60 2.60 2.60 2.59 2.60 2.60 2.60 2.59 2.59 2.60 2.59 2.59 2.60 2.60 2.59 2.60 2.60 2.60 2.60 2.59 2.60 2.60 2.60 2.60 2.60 2.60 2.60 2.60 2.60 2.59 2.60 2.60 2.60 2.60 2.59 2.60 2.60 2.60 2.60 2.60 2.60 2.59 2.60 2.59 2.60 2.60 2.60 2.59 2.60 2.60 2.60 2.59 2.60 2.60 2.60 2.60 2.60 2.60 2.60 2.60 2.59 2.60 2.60 2.59 2.60 2.60 2.60 2.60 2.59 2.60 2.59 2.59 2.60 2.60 2.59 2.60 2.60 2.59 2.60 2.60 2.60
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\c.php on line 13

    i tried the ip and port, and it wouldn't connect.

      dagon;10991681 wrote:

      i tried the ip and port, and it wouldn't connect.

      Since the IP belongs to a subnet reserved for private networks (e.g. LANs), did you first meet up with shakeelmscw and connect to his/her network?

        bradgrafelman;10991683 wrote:

        Since the IP belongs to a subnet reserved for private networks (e.g. LANs), did you first meet up with shakeelmscw and connect to his/her network?

        :quiet:shhhhhhhhhhhhhhhhhhh. some people have no wifi security :-)

          Security has nothing to do with it... hundreds if not thousands of devices all around the world probably share that same IP at this very moment. It's a private IP, not one that can be directly reached via the Internet in any way.

            bradgrafelman;10991680 wrote:

            Why not simply use [man]file_get_contents/man?

            mine data is a stream line and not saved in a file. Infect i need to read the data from my internal network device ip 192.168.0.150 port 10001
            if i put 192.168.0.150:10001 in browser address bar i am receiving new value every .5 second. i need to sum all these values in a variable and also count the total values received in 30 seconds. so i will be able to get single average value by dividing the sum of values by count of values. Please help me what code should i use?

              <?php
              $fp = fsockopen("192.168.0.150", 10001, $errno, $errstr, 30);
              if (!$fp) {
              echo "$errstr ($errno)<br />\n";
              } else {
              $out = "GET / HTTP/1.1\r\n";
              $out .= "Host: 192.168.0.150\r\n";
              $out .= "Connection: Close\r\n\r\n";
              fwrite($fp, $out);
              while (!feof($fp)) {
              echo fgets($fp, 128);
              }
              fclose($fp);
              }
              ?>

              i tried to use this code, which gives error after 30 second. as i mentioned in my 1st post.

                bradgrafelman;10991688 wrote:

                Security has nothing to do with it... hundreds if not thousands of devices all around the world probably share that same IP at this very moment. It's a private IP, not one that can be directly reached via the Internet in any way.

                yes i was joking. i do this for a living to.

                  dagon;10991692 wrote:

                  yes i was joking. i do this for a living to.

                  Yaar it is a matter of my life and you are joking..........😕

                    shakeelmscw;10991691 wrote:

                    i tried to use this code, which gives error after 30 second. as i mentioned in my 1st post.

                    shakeelmscw;10991678 wrote:

                    Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\c.php on line 13

                    And as the error message tells you, the maximum execution time is 30 seconds, which is exceeded after... 30 seconds. Solution: change max execution time: http://php.net/manual/en/function.set-time-limit.php

                      johanafm;10991697 wrote:

                      And as the error message tells you, the maximum execution time is 30 seconds, which is exceeded after... 30 seconds. Solution: change max execution time: http://php.net/manual/en/function.set-time-limit.php

                      My problem is this, I need some coding to do this work for 30 seconds.

                      mine data is a stream line and not saved in a file. Infect i need to read the data from my internal network device ip 192.168.0.150 port 10001
                      if i put 192.168.0.150:10001 in browser address bar i am receiving new value every .5 second. i need to sum all these values in a variable and also count the total values received in 30 seconds. so i will be able to get single average value by dividing the sum of values by count of values. Please help me what code should i use?

                      I need some working code to do this.

                        The coding should start reading values from 192.168.0.150 port 10001 in a variable.

                        The coding also read the count of values received. then we divide the sum of values by count of values and show the result on screen.

                          shakeelmscw;10991700 wrote:

                          My problem is this, I need some coding to do this work for 30 seconds.

                          No, your problem is that you need more than 30 seconds to do what you want. And as I explained in my previous post, you need to configure PHP to let you use more than 30 seconds of total execution time.

                          shakeelmscw;10991700 wrote:

                          mine data is a stream line and not saved in a file. Infect i need to […]

                          ... etc. Well, what you want to do, how you want to do it or why you want to do it still has nothing to do with your problem.

                          Increase max execution time. See my previous post.

                            If you understand that i should use more timeout, then please sugest me what coding i should use??

                            As i said above i want to achieve below

                            The coding should start reading values from 192.168.0.150 port 10001 in a variable.

                            The coding also read the count of values received. then we divide the sum of values by count of values and show the result on screen.

                              shakeelmscw wrote:

                              If you understand that i should use more timeout, then please sugest me what coding i should use??

                              See this post; it quotes a link to what you should use to increase the timeout.

                                Write a Reply...