Jump to content

Php Binary for sockets?


AbydosGater

Recommended Posts

Hi i have started reading some tutorials for working with sockets in php.

http://www.devshed.com/c/a/PHP/Socket-Programming-With-PHP/1/ The ones here on devshed seem to be good but on that file it says i need to run the code from my php binary, But i have never worked with sockets or php via command line before, only web based.

 

How do i get the php binary for running a socket?

 

Andy

Link to comment
https://forums.phpfreaks.com/topic/47959-php-binary-for-sockets/
Share on other sites

Ok i am running apache2triad 1.5 and it seems i have the binary CGI but i cant find a socket_server.php im supposed to have somewhere.. If i take a sample code from a tutorial..

#!/usr/local/bin/php –q

<?php
// Set time limit to indefinite execution
set_time_limit (0);

// Set the ip and port we will listen on
$address = '192.168.0.100';
$port = 9000;

// Create a TCP Stream socket
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
// Bind the socket to an address/port
socket_bind($sock, $address, $port) or die('Could not bind to address');
// Start listening for connections
socket_listen($sock);

/* Accept incoming requests and handle them as child processes */
$client = socket_accept($sock);

// Read the input from the client – 1024 bytes
$input = socket_read($client, 1024);

// Strip all white spaces from input
$output = ereg_replace("[ \t\n\r]","",$input).chr(0);

// Display output back to client
socket_write($client, $output);

// Close the client (child) socket
socket_close($client);

// Close the master sockets
socket_close($sock);
?> 

 

And when i try to run this in my browser it just loads and loads and loads but never finishes loading the page. could someone please tell me what im doing wrong?

(Oh and ps: why cant i edit my last post instead of posting this new one?)

Right i have been testing some things. And i have found out how to do it but im getting big errors    so i must be doing something wrong. When i open CMD and Change directory to my htdocs folder.. next i run the php.exe by entering the path to it into cmd followed by the script name.

Ie: c:\apache2triad\php\bin\php.exe myscript.php

But when i run this command i get two popup errors,

1) php.exe has made an attempt to load the C librarys incorrectly

2) ""PHP Startup: Unable to load dynamic library 'C:\apache2triad\php\extensions\php_curl.dll' - A dynamic (DLL) initialization routine failed"" But ive checked and the file is there!

 

But from there everything works fine once i click ok to the errors the script runs and it was a simple echo of hello world.. and it printed that to my cmd.

 

Now, if i try to run that script i have posted above. I still get the same errors, but it does run the script, i added in some ifs and echoes to make sure the sockets where created and binded and it all worked.

But when i try to telnet to my server telnet:\\192.168.1.136:9000 or telnet:\\localhost:9000 i just get a blank cmd and when i type anything i just get an error, connection with host lost.

 

Could someone please tell me what im doing wrong either case, the errors or the sockets not working?

 

Andy

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.