Page 1 of 1

SOCKETS IN PHP

Posted: Sun Mar 29, 2009 7:13 am
by kushaljutta
Can anybody help me in creating sockets in php

1.How to create a socket

2.How to send & receive responce from client to server..

thanks in advance

Re: SOCKETS IN PHP

Posted: Sun Mar 29, 2009 8:33 am
by php_east
what have you tried ?

Re: SOCKETS IN PHP

Posted: Tue Mar 31, 2009 1:06 am
by kushaljutta
in my project i have done module in that

ie..

writing data into xml file with these sockets only

actually this is gaming project

1...player sends the data to player2 then in this case player2 recieves that data whenever player1 sends that..

in this case i used xml's for this player 2 continuously check whether player1 sends the data or not...

but it is the worst case

so to resolve this problem i want to use sockets..

please help me....

actually my requirement is

==================
create a socket afer that it receives the xml data and writes that xml data in a socket.

please boss

Re: SOCKETS IN PHP

Posted: Tue Mar 31, 2009 5:06 am
by php_east
my recomendation is to use ajax, as it has on ready events and read/writes into xml directly. this saves yo a lot fo headache of using lower level sockets to do what can easily be done using ajax. if there is some very good reason you wish to use socket, then by all means do so, but most of what is required can be achieved with ajax.

Re: SOCKETS IN PHP

Posted: Wed Apr 01, 2009 8:04 am
by kushaljutta
thanQ for sending reply

but i need it sockets only

please boss please

help me in how to write data in socket

Re: SOCKETS IN PHP

Posted: Wed Apr 01, 2009 8:06 am
by kushaljutta
i got some code in sockets

<?php
$address="74.54.206.242";
$port=80;
$socket=socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
echo "socket created".$socket;
$res=socket_connect($socket,$address,$port);
echo "<br/>Result".$res;
socket_write($socket,"get /index.php http/1.0\n\n");
$result="";
while($read=socket_read($socket,1024)){
$result.=$read;

}
echo "<br/>Result received:'$result'\n";
socket_close($socket);
?>

like this code i want to write data into sockets...

the outpt of this code is
===========================
socket createdResource id #1
Result1
Result received:'HTTP/1.1 404 Not Found Date: Wed, 01 Apr 2009 13:05:15 GMT Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Content-Length: 521 Connection: close Content-Type: text/html; charset=iso-8859-1
Not Found

The requested URL /index.php was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at f6.e2.354a.static.theplanet.com Port 80
'

Re: SOCKETS IN PHP

Posted: Thu Apr 02, 2009 7:52 am
by kushaljutta
hi PHP_ease ru there...

Re: SOCKETS IN PHP

Posted: Thu Apr 02, 2009 10:37 am
by php_east
well, you already have the codes, and so i don't understand what you wanted. if it's in learning on how to use sockets, then i would suggest you play with the codes you already have. and enjoy it while you're at it !. you will learn plenty that way undoubtedly. :D

Re: SOCKETS IN PHP

Posted: Sat Apr 04, 2009 3:00 am
by kushaljutta
hi

thanks for the reply

didnt you understand that code which i already sent..

just tell me one thing that

how to create a socket
2.how to bind that socket
3.how to write the data in to the socket
4.how to read the data in the socket which are written by us
if you send me those details ill really thankful to you...

Re: SOCKETS IN PHP

Posted: Sat Apr 04, 2009 6:18 am
by php_east
kushaljutta wrote: how to create a socket
2.how to bind that socket
3.how to write the data in to the socket
4.how to read the data in the socket which are written by us
if you send me those details ill really thankful to you...
the answers are ALL in the codes you posted.
it is all there, so you can study them, look at each and everyone using the PHP manual, and you will find all the answers there. there is of course a lot lookup to do, but that is how everyone learns.

if you are stuck on specifics, i can answer them.

Re: SOCKETS IN PHP

Posted: Mon Apr 06, 2009 4:43 am
by kushaljutta
thanks for the reply

i already tried all those things but they gave me fatal errors like

cannot call unefined function....

pipe was broken

and finally

maximum time limit exceeded..

my request is if you have a worked examples please give that example for me

i searched in the google but all those things are not running well....

my need is to run these sockets in browsers..but i saw maximum examples are worked in shell script..

please ...

Re: SOCKETS IN PHP

Posted: Tue Apr 07, 2009 9:40 pm
by php_east
that is very strange indeed becasue i have tried your codes and they work, very well.
i even tried googles site with it and it works too.

so it is likely your problem is your setup, not the codes. before anything else, ensure you have a stable & reliable setup. otherwise, you surely won't get far.

Re: SOCKETS IN PHP

Posted: Wed Apr 08, 2009 6:11 am
by kushaljutta
can you send me those worked examples..

cant i change my configuration setup in php.ini