For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > July 2004 > php socket question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author php socket question
Sticks

2004-07-27, 8:56 am

hello

i want to be able to send a packet to a http server and receive the
response, but i'm not quite sure how to do it. i thought of using
sockets, and although i have worked out how to send data to the http
server, i have no idea how to receive the responses.

any help wuld be greatly appreciated.

this is what i've got so far. i know that the server is receiving the
data because i have employed this technique before, only previously i
did not need to receive the response.

<?php

function login()
{
$data = "POST /admin/default.asp HTTP/1.1\r\n";
$data .= etc etc etc

$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TC
P);
$connection = socket_connect($socket,'(*IP ADDRESS*)','80');

socket_write($socket,$data);
socket_close($socket);
}

login();

?>
Zurab Davitiani

2004-07-27, 8:56 am

Sticks wrote:

> <?php
>
> function login()
> {
> $data = "POST /admin/default.asp HTTP/1.1\r\n";
> $data .= etc etc etc
>
> $socket = socket_create(AF_INET,SOCK_STREAM,SOL_TC
P);
> $connection = socket_connect($socket,'(*IP ADDRESS*)','80');
>
> socket_write($socket,$data);
> socket_close($socket);
> }
>
> login();
>
> ?>


Avoid using HTTP 1.1 - in my experience, PHP4 doesn't handle the chunked
transfer encoding very well. I don't know if they have sorted this out in
later versions though. The examples you are looking for are here:

http://www.php.net/manual/en/ref.sockets.php
sinan

2004-07-27, 3:58 pm

Take a look at the php manual item about fsockopen() at www.php.net .
There are examples too.
Manuel Lemos

2004-07-27, 8:55 pm

Hello,

On 07/27/2004 07:09 AM, Sticks wrote:
> i want to be able to send a packet to a http server and receive the
> response, but i'm not quite sure how to do it. i thought of using
> sockets, and although i have worked out how to send data to the http
> server, i have no idea how to receive the responses.


It is like reading and writing files with fread fgets.

Anyway, to not reinvent the wheel you may want to try this http client
class that supports posting forms, redirection, collecting cookies, etc..

http://www.phpclasses.org/httpclient


--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Chung Leong

2004-07-27, 8:55 pm

"Sticks" <barton_finkle@hotmail.com> wrote in message
news:41062a37$0$22405$5a62ac22@per-qv1-newsreader-01.iinet.net.au...
> hello
>
> i want to be able to send a packet to a http server and receive the
> response, but i'm not quite sure how to do it. i thought of using
> sockets, and although i have worked out how to send data to the http
> server, i have no idea how to receive the responses.
>
> any help wuld be greatly appreciated.
>
> this is what i've got so far. i know that the server is receiving the
> data because i have employed this technique before, only previously i
> did not need to receive the response.


See http://www.php.net/stream_context_create


--
Obey the Clown - http://www.conradish.net/bobo/


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com