How to create and run server socket on Hosting Server

Posted on 2009-04-18
Last Modified: 2012-05-06

I own a web server Windows NT based and it supports both .NET, PHP and socket support too.

I have sample server socket code and tested in linux it working fine but i run the code in terminal mode in linux ==> ./serversocket.php.

I want to know how to run the same php file in hosting server.



$host = "";

$port = 6556;


$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");

$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");

$result = socket_listen($socket, 3) or die("Could not set up socket listener\n");

while (true)


$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");

$input = socket_read($spawn, 1024) or die("Could not read input\n");

$input = trim($input);

$output = strrev($input) . "\n";

socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n");





Open in new window

Question by:ksprabha_p
    1 Comment
    LVL 13

    Accepted Solution

    If you want to run it from the command line, use the PHP-CLI interpreter, just add (on the first line of the file)

    #!/usr/bin/php -q

    So Linux know where to look for the interpreter. You can also find it with

    which php

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now