PHP Socket Programming Tutorial

Every programming language enable to use socket programming to provide the communication mechanism between two processes on the same or different machine. PHP is the one of the programming language that able to use the socket. A Socket is mostly used in a client-server application framework. There have many application-level protocols like FTP, HTTP, and HTTPS to make use of sockets to establish connection between client and server.

Create a PHP file

Open your PHP editor and create a php file name “server”. Below is the server.php code and insert the following code.

Open command prompt

Open your cmd and type php (path)/(your-file-name). Way to open cmd : search cmd in the bottom bar.

php socket programming

Edit client.php file

After that create one more php file name “client” and insert the below code.

Open second command prompt

Open another command prompt,  insert the client.php path. Below are example.

Check client respond

After that, you will see the server(1st command prompt) respond from the client(2nd command prompt).

(PHP Socket Programming)

Source Code

(Visited 3,101 times, 1 visits today)

Kristofer Ng

A crazy android and web developer. Passion on developing android application and exploring new technology as a hobby.

You may also like...

1 Response

  1. cool says:

    I want to apply same on browser .. please help

Leave a Reply

Your email address will not be published. Required fields are marked *