Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Very Basic php

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Very Basic php

Postby mikeincousa » Mon Sep 09, 2013 4:05 pm

I am trying to get a handle on the basics of port I/O.

The first script on this page seemed like an easy start.
Simply open an close a port using php seemed like an easy first step, and that's what I expected from this srcipt.

http://php.net/manual/en/function.fsockopen.php
(substituting my fixed IP address for example.com)

***************
<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: http://www.example.com\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>
# all that renders " Connection timed out (110) "
**********

I monitor the activity on the port with #netstat -plnt

The srcript does not open the port.

If I open the port with nc -l 6023 the script does not close it.

Could some kind soul help me get a tiny-toe-hold?

Suggest alternates for learning how to open and close a port with php?

Not being able to get a single example working as expected is discouraging.

Thanks
mikeincousa
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed Jun 26, 2013 8:17 pm

Re: Very Basic php

Postby johnj » Mon Sep 09, 2013 8:05 pm

Are you sure that this port 80 is free and that no other application is using it??. Also, try to use error validation routines when you do activities like opening and closing ports, fwrite, fget etc so that you know what is going wrong or sometimes why it is going wrong.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 5 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.