Very Basic php

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

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

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.
(substituting my fixed IP address for

$fp = fsockopen("", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host:\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
# 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.


php-forum Super User
php-forum Super User
Posts: 1803
Joined: Thu Mar 10, 2011 5:07 pm

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.

Post Reply