PHP can open sockets on remote or local hosts. Here is a hands-on example of using
such a socket: getting connected to a Usenet News Server, talking to this server,
and downloading some articles for a precise newsgroup.
Sockets are opened using fsockopen(). This function is both available in PHP3 and
PHP4. It uses the following prototype :
For the Internet domain, it will open a TCP socket connection to hostname on port port.
hostname may in this case be either a fully qualified domain name or an IP address. For UDP
connections, you need to explicitly specify the protocol: udp://hostname. For
the Unix domain, hostname will be used as the path to the socket, port must be set to 0 in
this case. The optional timeout can be used to set a timeout in seconds for the connect system call.
Accessing a Usenet News Server requires using a specific protocol, called NNTP and standing for Network News Transfer Protocol.
This protocol is higly detailed in RFC977 (Request For Comment number 977), which is available at :
http://www.w3.org/Protocols/rfc977/rfc977.html
This document described precisely how to connect to and then dialog with the NNTP server thanks to the various commands available for the task.
Connecting to the NNTP server requires knowing its hostname (or IP address) and the port it is listening on. You should include a timeout so that an unsuccessful attempt at connecting does not "freeze" the application.
| Comments: |
| RE: Sockets and Half-Life | Justin Frydman | 02/14/06 01:56 |
| RE: use php exec() to Control Parallel Port | coolvista | 10/31/05 13:24 |
| RE: Retrieving article from usenet | sangeeta chakraborty | 10/15/05 00:24 |
| saving scripts | Rogy | 04/05/05 08:15 |
| how to access external email behind my proxy | relly | 02/15/05 20:53 |
| RE: Sockets and Half-Life | Turk | 01/25/05 13:38 |
| And how about those fairies? | Sex | 12/05/04 04:48 |
| For some reason, | Sex | 12/05/04 04:47 |
| PLease, how Can i download. | Sex Beplaced Ru | 12/05/04 04:43 |
| ummmmmmmmm whats this mummy?? | Sex Beplaced Ru | 12/05/04 04:34 |
| This was closely associated with the rebirth of | Freeflashonlinegames Com | 12/05/04 04:33 |
| Thanks. I hope other people test it too. | Freeflashonlinegames Com | 12/05/04 04:33 |
| This was closely associated with the rebirth of | Sex Beplaced Ru | 12/05/04 04:32 |
| die Reet is anders een gemene man... | Freeflashonlinegames Com | 12/05/04 04:31 |
| You are right ofcourse... But... | Sex Beplaced Ru | 12/05/04 04:31 |
| For some reason, | Sex Beplaced Ru | 12/05/04 04:29 |
| Were there ever real witches? | Sex | 12/05/04 04:28 |
| This was closely associated with the rebirth of | Sex | 12/05/04 04:26 |
| What?, don't they know who we are? | Freeflashonlinegames Com | 12/05/04 04:25 |
| Finally figured this out - my | Sex | 12/05/04 04:25 |
| If not, what were all the witch trials about? | Sex | 12/05/04 04:23 |
| PLease, how Can i download. | Freeflashonlinegames Com | 12/05/04 04:08 |
| RE: HTTP Proxy Servers and PHP Sockets | Rev Aaron | 04/23/04 10:47 |
| RE: Quake III Protocol | Kyle | 04/02/04 13:42 |
| RE: Sockets not working...Please help | usman shahid | 10/19/02 04:58 |
| Retrieving ip from url | Smoske | 09/20/02 15:19 |
| Sockets not working...Please help | Renny | 09/19/02 14:03 |
| Sned HTML message to all connected client | Jim | 09/13/02 08:17 |
| How to use PHP Control Paralle Port | Pyrawate | 09/09/02 00:32 |
| How to use PHP Control Paralle Port | Pyrawate | 09/08/02 23:59 |
| RE: Retrive client's ip address | Quan Mac | 09/04/02 00:54 |
| RE: How to open sockets from behind proxy server | Ionut Daia | 08/22/02 20:39 |
| ADVANCED PHP SOCKETS | Gustavo Almeida | 08/14/02 14:34 |
| ADVANCED PHP (SOCKET) | Gustavo Almeida | 08/14/02 14:27 |
| timeout does not work | Osman Darcan | 08/06/02 19:32 |
| RE: How to open sockets from behind proxy server | zingit | 07/18/02 04:53 |
| Stuck | Bamma | 06/29/02 17:57 |
| RE: Sockets and Half-Life full script here | NvE0s | 06/26/02 19:41 |
| passing parameter | Vit | 06/25/02 23:24 |
| Quake III Protocol | Johan | 06/24/02 15:24 |
| GET?? | Giuseppe | 06/20/02 05:22 |
| Retrive client's ip address | John | 06/16/02 03:17 |
| Script for negotiating proxy with user auth. | Xixulon | 06/14/02 10:52 |
| RE: How to open sockets from behind proxy serve | Xixulon | 06/14/02 10:49 |
| Wap -> Website -> Computer shutdown. | Marek Miettinen | 06/14/02 06:56 |
| RE: IRC Socket? | Bryan | 06/12/02 01:36 |
| RE: Browser Chat client | Max Mo | 06/11/02 08:10 |
| RE: PHP sockets/networks | Kamran | 05/07/02 03:49 |
| RE: IRC Socket? | rubbi | 05/03/02 13:05 |
| RE: PHP sockets/networks | Morrissey | 04/27/02 03:25 |
| html codes | marie shelton | 04/22/02 07:23 |
| Proxy | Tom | 04/15/02 08:59 |
| RE: Re Sockets and Half-Life | bstanescu | 04/08/02 05:52 |
| PERL Sockets AND PHP Sockets | popnikos | 04/03/02 09:24 |
| RE: Browser Chat client | bluBattery | 03/13/02 14:54 |
| cookies | mohd | 03/09/02 16:37 |
| Accessing POP3 mailbox using PHP Sockets | Arun G P Dutt | 03/07/02 00:41 |
| RE: socket code | Michelle | 02/26/02 17:58 |
| RE: Sockets and Half-Life | Dave | 02/18/02 18:46 |
| RE: Browser Chat client | Rob_Earl | 02/05/02 22:14 |
| RE: How to redirect in LAN | Rob | 02/05/02 21:54 |
| RE: importing a html page in a php script | Rob | 02/05/02 21:32 |
| RE: How to redirect in LAN | Rob | 02/05/02 21:30 |
| RE: Sockets and Half-Life | Rob | 02/05/02 15:46 |
| RE: PHP telnet client? | Per-Ingar Auberg | 02/02/02 06:03 |
| Telnet scripting from PHP | Per-Ingar Auberg | 02/02/02 06:00 |
| RE: How to open sockets from behind proxy server | Valberg Larusson | 01/19/02 01:02 |
| socket code | Colleen | 01/16/02 16:47 |
| RE: How to post a form to another... | Palan | 01/12/02 17:51 |
| socket response-urg!!! | sands | 01/09/02 10:50 |
| How can I change xml file to php array | S.Murali Krishna | 01/08/02 05:21 |
| How to redirect in LAN | mk4 | 01/05/02 05:28 |
| RE: Sockets and Half-Life | Ruud Kamphuis | 01/01/02 09:05 |
| RE: Sockets and Half-Life | Dinesh | 12/30/01 14:46 |
| RE: PHP telnet sockets(was client) | Gulopine | 12/20/01 11:14 |
| importing a html page in a php script | joe | 12/14/01 20:11 |
| Retrieving article from usenet | Bill | 12/12/01 18:05 |
| RE: How to open sockets from behind proxy server | Steven Chalker | 12/11/01 17:04 |
| How to open sockets from behind proxy server | Satish Krishna | 12/04/01 06:43 |
| Display pictures which are attached? | valerie | 11/29/01 14:16 |
| Can pictures be displaid which are attached? | valerie | 11/28/01 18:41 |
| opening sockets in php | Yogesh Randhawa | 11/28/01 07:33 |
| PHP sockets/networks | Armando P. | 11/21/01 05:21 |
| How can I catch a socket in action? | Albert MAYE | 11/05/01 09:58 |
| How to post a form to another... | Marcel | 11/05/01 08:25 |
| And now, what's is the final script? | mc-no-solard | 11/04/01 12:41 |
| Can I display pictures which are attached? | Jens | 11/03/01 10:41 |
| RE: saving php output in html file | Tomas | 10/29/01 12:51 |
| RE: how to enable socket() in PHP | archi69 | 10/21/01 23:59 |
| RE: Sockets and Half-Life | huib bakker | 10/07/01 07:46 |
| saving php output in html file | andrea | 09/28/01 05:49 |
| all about sockets | lavanya | 09/28/01 05:28 |
| Browser Chat client | LeeWynn | 09/15/01 19:42 |
| Question | Steven C | 09/07/01 10:31 |
| FTP connection | J.Bijleveld | 09/04/01 08:00 |
| RE: I would like to known more about php | Ger van Vugt | 08/18/01 08:58 |
| how to enable socket() in PHP | Diou | 07/30/01 03:02 |
| RE: Sockets and Half-Life | ady | 07/28/01 09:33 |
| How to make only on query | Claude | 07/27/01 02:56 |
| RE: HTTPS Sockets | dRago | 07/25/01 04:39 |
| RE: I would like to known more about php | Phillip Oertel | 07/24/01 04:52 |
| SOCKET PHO | Jose Luis Castro | 07/18/01 13:09 |
| help me!!! | ice_berg16 | 07/18/01 04:58 |
| RE: Sockets and Half-Life | paul | 07/09/01 22:55 |
| RE: PHP telnet sockets(was client) | OmagaSohe | 07/09/01 05:46 |
| RE: IRC Socket? | Nilo | 07/02/01 11:41 |
| RE: IRC Socket? | zeke | 07/02/01 02:48 |
| Page Links | Ravinder singh | 06/29/01 02:44 |
| RE: IRC Socket? | Bertrand DUNOGIER | 06/26/01 04:12 |
| Sounds with PHPCHAT | Alan | 06/25/01 12:53 |
| I would like to known more about php | Hugo Ivan | 06/18/01 10:31 |
| is the socket() function available in windows | Paul Villavicencio | 06/13/01 07:57 |
| RE: HTTPS Sockets | Uwi | 06/13/01 07:34 |
| Which nntp server to use? | Seb Delcampe | 06/07/01 10:59 |
| PHP Sockets... | Kyle Olsen | 06/06/01 14:41 |
| RE: PHP telnet client? | Kyle Olsen | 06/04/01 11:30 |
| RE: HTTPS Sockets | Jordan | 05/25/01 09:58 |
| replacing characters | Mike | 05/22/01 01:57 |
| Sockets and Half-Life | Rafael Bastidas | 05/21/01 11:28 |
| Example at phpindex.com/ng | Alex | 05/21/01 08:17 |
| Getting Headers Only | Sean | 05/20/01 01:11 |
| RE: HTTPS Sockets | Erwin | 05/16/01 10:00 |
| HTTPS Sockets | Jon Thomas | 05/13/01 18:32 |
| PHP telnet client? | jchc | 05/12/01 23:50 |
| RE: IRC Socket? | steve | 05/11/01 16:03 |
| RE: decoding attachments | Onno Benschop | 05/08/01 19:23 |
| Achive this from behind a proxy ! | Steve haemelinck | 05/06/01 06:19 |
| RE: PHP Sockets on Windows | bmpc | 05/06/01 04:49 |
| RE: Oy, why did the RFC specify numeric codes? | Armel FAUVEAU | 05/03/01 09:45 |
| RE: IRC Socket? | Armel FAUVEAU | 05/03/01 09:42 |
| RE: IRC Socket? | Mathieu 'CaPS' Kooiman | 05/02/01 23:20 |
| RE: Oy, why did the RFC specify numeric codes? | Mathieu 'CaPS' Kooiman | 05/02/01 23:18 |
| IRC Socket? | Ninconvert | 05/02/01 17:33 |
| RE: Oy, why did the RFC specify numeric codes? | Armel FAUVEAU | 05/02/01 17:20 |
| Radius check using PHP+sockets | O. van Zandwijk | 05/02/01 15:07 |
| Oy, why did the RFC specify numeric codes? | Mathieu 'CaPS' Kooiman | 05/01/01 05:59 |
| RE: disconneting .... | Dave | 05/01/01 05:00 |
| RE: IMAP functions? | Dave | 05/01/01 04:59 |
| decoding attachments | Christian Lund | 04/30/01 14:02 |
| RE: IMAP functions? | Justin Plock | 04/30/01 11:08 |
| PHP Sockets on Windows | C Clarke | 04/30/01 06:39 |
| RE: IMAP functions? | Armel FAUVEAU | 04/29/01 17:47 |
| RE: IMAP functions? | Xan Nick | 04/29/01 10:33 |
| IMAP functions? | Justin Plock | 04/28/01 01:24 |
| disconneting .... | E.Daspet | 04/28/01 00:49 |
|
If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.
|