Please help me on this,I am creating simple socket connection that listen to port 80 and i will put this to my server and I am using wampserver,…where do i put this mysocket.php ? in the root of my www?
Thank you in advance.
Please help me on this,I am creating simple socket connection that listen to port 80 and i will put this to my server and I am using wampserver,…where do i put this mysocket.php ? in the root of my www?
Thank you in advance.
@jemz Can you show us what that mysocket.php file contains?
This is the socket file that i want to put in my server.
<?php
// Server IP address
$address = "xx.xxx.xxx.xxx";
// Port to listen
$port = 80;
$mysock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($mysock,$address, $port) or die('Could not bind to address');
socket_listen($mysock, 5);
$client = socket_accept($mysock);
// read 1024 bytes from client
$input = socket_read($client, 1024);
// write received gprs data to the file
writeToFile('gprs.log', $input);
socket_close($client);
socket_close($mysock);
?>
<?php
function writeToFile($strFilename, $strText) {
if($fp = @fopen($strFilename,"w")) {
$contents = fwrite($fp, $strText);
fclose($fp);
return true;
} else {
return false;
}
}
?>
This doesn’t look like a script that should be called from a web server or URL, this is a “command line” script. I’m not sure it will work on Windows, but you could give it a try.
Here’s the official doc for command line PHP :http://www.php.net/manual/en/install.windows.commandline.php
The documentation for using php sockets clearly provides a resource for learning more about them and the URL to a resource for those whom are unfamiliar
Hi jemz,
If you’re writing a script to listen to a port, you don’t want to be serving it via wampserver. A HTTP server like Apache (or nginx) is listening on a port (usually port 80) for incoming HTTP requests and then returning a response. To listen on a port with your script, you’ll need to run it from the command line (as xMog suggests), and probably open the corresponding port on your firewall. Also, I wouldn’t choose port 80 for you script, as it’s used by web servers and by programs like Skype.
C:\\PHP5\\php.exe -f "C:\\PHP Scripts\\script.php" -- -arg1 -arg2 -arg3
what is that arg1 arg2 arg3 stands for?
Thank you in advance.
They are just examples to show how you would pass arguments to a script from the command line.