| | |
About socket programming in php
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Dear All,
Sorry for my frequent questions in this forum. I have came here with a lot of questions. I need help in socket programming in php. For example, Lets consider I have a ip number and port number. Using this ip and port values i want to send a message to server though sockets. The server handles the message and reply to my machine through sockets. After that I wants to display the message in the front end.
Its possible to obtain this using php sockets....
Please guide me....
Thanks in advance...
Sorry for my frequent questions in this forum. I have came here with a lot of questions. I need help in socket programming in php. For example, Lets consider I have a ip number and port number. Using this ip and port values i want to send a message to server though sockets. The server handles the message and reply to my machine through sockets. After that I wants to display the message in the front end.
Its possible to obtain this using php sockets....
Please guide me....
Thanks in advance...
Yes, of course.
Take a look at the PHP stream (socket) functions: http://www.php.net/stream
If you look at the page about at the example: Making a POST request to an https server, you'll notice it is a socket connection to the port 443 over SSL.
Stream functions allow any protocol however.
Usually on a socket connection, you will do something like:
Open a socket using fsockopen().
write to the socket with fwrite()
read from the stream with fread() or fgets() till end of the stream, feof()
wait a few seconds with sleep()
read.. write.. etc.
What protocol are you using this for? PHP may have abstracted functions for each protocol so you don't have to deal with the raw socket...
Take a look at the PHP stream (socket) functions: http://www.php.net/stream
If you look at the page about at the example: Making a POST request to an https server, you'll notice it is a socket connection to the port 443 over SSL.
Stream functions allow any protocol however.
Usually on a socket connection, you will do something like:
Open a socket using fsockopen().
write to the socket with fwrite()
read from the stream with fread() or fgets() till end of the stream, feof()
wait a few seconds with sleep()
read.. write.. etc.
What protocol are you using this for? PHP may have abstracted functions for each protocol so you don't have to deal with the raw socket...
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
dont forget to close the socket connection with fclose(). On some systems the memory allocated for this will be allocated indefinitely unless you close the socket specifically...
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
Join Date: Oct 2008
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
Yes, of course.
Take a look at the PHP stream (socket) functions: http://www.php.net/stream
What protocol are you using this for? PHP may have abstracted functions for each protocol so you don't have to deal with the raw socket...
I have a same question. I mean, if I want to send a little bit of message (ex: "pingIPok") from IP 192.168.0.1:80 to IP 192.168.0.7:80, and the IP target will replay with message (ex: "message receive for pingIPok") using socket function on php (port = 80). Then make a record of sql table for each of messages sent and received. How to do it with PHP, please give me an example with complete code.
Thank for your replay
I hope you will replay my question Last edited by hairulazami; Oct 15th, 2008 at 10:08 pm.
•
•
•
•
I have a same question. I mean, if I want to send a little bit of message (ex: "pingIPok") from IP 192.168.0.1:80 to IP 192.168.0.7:80, and the IP target will replay with message (ex: "message receive for pingIPok") using socket function on php (port = 80). Then make a record of sql table for each of messages sent and received. How to do it with PHP, please give me an example with complete code.
Thank for your replayI hope you will replay my question
PHP Syntax (Toggle Plain Text)
file_get_contents();
What you want to do is make a http socket connection over the regular port 80, so this is nothing more then downloading a webpage over HTTP.
So if you had a PHP page, called: receive_ping.php
Then you could just have the code to write to the database in that.
On your remote server do:
PHP Syntax (Toggle Plain Text)
file_get_contents('http://remote_site.com/receive_ping.php');
The php page can gather the IP of the site doing the ping and other info and insert that into the database.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
Join Date: Oct 2008
Posts: 2
Reputation:
Solved Threads: 0
o'right, I just read details of the current function on my php manual cfm
so, If the condition like that, I can use this code to implementation it:
OR BASED ON YOUR FUNCTION ADVICED
so, If the condition like that, I can use this code to implementation it:
PHP Syntax (Toggle Plain Text)
<? //put file function function putItNow($source) { $saveto = "D:\dreserv\www\dredsync\dds-includes\images\down\img3.jpg"; $putdata = fopen($source, "r"); /* Open a file for writing */ $fp = fopen($saveto, "w"); /* Read the data _MAX_UPLOADED_FILE KB at a time and write to the file */ while ($data = fread($putdata, 1024)) fwrite($fp, $data); fclose($fp); fclose($putdata); } putItNow("http://192.168.0.7:1441/dds-includes/images/syncronized/img3.jpg"); ?>
OR BASED ON YOUR FUNCTION ADVICED
PHP Syntax (Toggle Plain Text)
<? $getContent = file_get_contents("http://192.168.0.7:1441/dds-includes/lib/downloadlist.txt"); echo '<BR>'.$getContent; ?>
![]() |
Similar Threads
- Socket Programming... (C#)
- I Can'f Find a Hosting Company that allows me to do socket programming! (PHP)
- C++ socket programming (C++)
- How to send a double value in socket programming (C)
- Core PHP Programming to Build Dynamic Websites (PHP)
- Socket programming + porting Unix to Win32 (C)
Other Threads in the PHP Forum
- Previous Thread: how to create an email address
- Next Thread: how to make a voice & video chat?
| Thread Tools | Search this Thread |
action address ajax apache api array auto autoincrement beginner binary broken cakephp checkbox class classes cms code cron curl database date dehasher display domain dynamic echo email error errorlog fatalerror file files folder form format forms function functions google href htaccess html image include insert interactive ip java javascript joomla limit link load login mail malfunctioning masterthesis menu mlm multiple mysql nodes oop paypal pdf php popup problem query radio ram random record recursion reference remote return script search server sessions sms source space sql syntax system table tutorial unset update upload url validation validator variable video web websitecontactform youtube






