Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to create and run server socket on Hosting Server

Posted on 2009-04-18
1
Medium Priority
?
490 Views
Last Modified: 2012-05-06
Hi,

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.
serversocket.php
 
<?
$host = "xxx.xx.xx.xxx";
$port = 6556;
set_time_limit(0);
$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");
socket_close($spawn);
}
socket_close($socket);
?>

Open in new window

0
Comment
Question by:ksprabha_p
1 Comment
 
LVL 13

Accepted Solution

by:
Xyptilon2 earned 375 total points
ID: 24179500
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

578 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