PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 307,153 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,598 people online right now. Registration is fast and FREE... Join Now!




WAMP server & Sockets

 

WAMP server & Sockets

KuroTsuto

17 Feb, 2009 - 11:45 AM
Post #1

D.I.C Head
Group Icon

Joined: 13 Feb, 2009
Posts: 104



Thanked: 12 times
Dream Kudos: 25
My Contributions
Hey,

one of the projects that I'm throwing around in my spare time involves a server-side application interacting with a MySQL database through PHP scripts. I'm not one to set up my entire webserver from scratch, so I simply utilized the WAMP tool to install them all. I would really like to remove the whole aspect of having my application interact through the HTTP protocol, and so I would like to use PHP for CLI scripts and just have them running in the background and listening on specified ports. However, WAMP seems to really dislike its included sockets module, for whenever I run a script from the command line through any of the three binaries (php.exe, php-win.exe, or php-cgi.exe), I am only returned with an error stating that the first socket-related function encountered is undefined. I have tried manually setting both of the php.ini files that appear in a WAMP install (php.ini and phpForApache.ini), yet neither seem to yield different results.

On one final note, I understand that this issue belongs more appropriately in the WAMP support forums, but it is no stretch to say the WAMP support is commonly less than ideal....

Thanks in advance for whatever aid you might offer wink2.gif

User is offlineProfile CardPM
+Quote Post

 
Reply to this topicStart new topic
Replies(1 - 8)

musya

RE: WAMP Server & Sockets

18 Feb, 2009 - 12:50 PM
Post #2

D.I.C Addict
Group Icon

Joined: 25 Apr, 2007
Posts: 726



Thanked: 8 times
Dream Kudos: 50
My Contributions
Quick question why do you run it through one of the three binaries?
User is offlineProfile CardPM
+Quote Post

KuroTsuto

RE: WAMP Server & Sockets

20 Feb, 2009 - 11:28 AM
Post #3

D.I.C Head
Group Icon

Joined: 13 Feb, 2009
Posts: 104



Thanked: 12 times
Dream Kudos: 25
My Contributions
Sorry for my late reply... I run it through one of the three binaries because I am unaware of any other method to run a command-line script... is there something I might be missing?
User is offlineProfile CardPM
+Quote Post

pr4y

RE: WAMP Server & Sockets

20 Feb, 2009 - 11:31 AM
Post #4

Location: 127.0.0.1
Group Icon

Joined: 19 Sep, 2008
Posts: 615



Thanked: 29 times
Dream Kudos: 175
My Contributions
What you are missing is that you aren't supposed to "run" php.exe. What you need to do here is load the Shell, and execute your .PHP files by using the following command:

shell

php /path/to/file.php


Hope this helps!
User is offlineProfile CardPM
+Quote Post

KuroTsuto

RE: WAMP Server & Sockets

22 Feb, 2009 - 09:48 AM
Post #5

D.I.C Head
Group Icon

Joined: 13 Feb, 2009
Posts: 104



Thanked: 12 times
Dream Kudos: 25
My Contributions
Thanks for the reply, and sorry for the late reply, once more. That is actually how I'm parsing/executing my script; opening the shell and executing the binary through the command line with the absolute path to my script as an argument. But instead of using
CODE
php /path/to/file.php
as you suggested, I am using
CODE
php -f /path/to/file.php
as -f is the command line option to parse and execute a script file. In really nothing more than desperation, I have replaced "php" with "php-cgi" and "php-win" as the original "php" is a command to execute the "php.exe" binary, and thus I thought attempting to parse/execute the script through one of the other two binaries might have a different result. I can assure you that the method by which I am executing the script is not at fault, for I may parse and execute any script that does not involve socket-related functions without error. It is more the proper integration of the socket module into WAMP that appears to be faulty, as per my original post.

This post has been edited by KuroTsuto: 22 Feb, 2009 - 09:57 AM
User is offlineProfile CardPM
+Quote Post

cam888

RE: WAMP Server & Sockets

22 Feb, 2009 - 12:49 PM
Post #6

New D.I.C Head
*

Joined: 20 Feb, 2009
Posts: 26


My Contributions
On Linux, command line php has a different php.ini, this may be the case for windows.
User is offlineProfile CardPM
+Quote Post

musya

RE: WAMP Server & Sockets

22 Feb, 2009 - 01:00 PM
Post #7

D.I.C Addict
Group Icon

Joined: 25 Apr, 2007
Posts: 726



Thanked: 8 times
Dream Kudos: 50
My Contributions
Honestly it might just be a windows problem not the install of the server.
User is offlineProfile CardPM
+Quote Post

JackOfAllTrades

RE: WAMP Server & Sockets

22 Feb, 2009 - 07:00 PM
Post #8

I exist to Google your problems.
Group Icon

Joined: 23 Aug, 2008
Posts: 5,324



Thanked: 454 times
Dream Kudos: 50
Expert In: Being annoyed with lazy people.

My Contributions
Search your drive for php.ini (although it's likely just underneath the wamp install directory) and open it.

Find the following line:
CODE
;extension=php_sockets.dll


Delete the leading semi-colon (which comments that line out).

Save the file.

Enjoy socket goodness. For example this program:
php
<?php
$socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname("tcp"));
if (!$socket)
{
die("Socket creation failed: " . socket_last_error());
}

if (!socket_connect($socket, "208.67.217.230", 80))
{
echo("Socket connect failed: " . socket_last_error());
socket_close($socket);
exit();
}

$request = "GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n";
if (!socket_send($socket, $request, strlen($request), 0))
{
echo("Socket send failed: " . socket_last_error());
socket_close($socket);
exit();
}

$response = "";
if (!socket_recv($socket, $response, 8192, 0))
{
echo("Socket recv failed: " . socket_last_error());
socket_close($socket);
exit();
}

echo ("Received $response \n");
socket_close($socket);
?>


Returns:
CODE
C:\Documents and Settings\Jack>\wamp\bin\php\php5.2.6\php.exe -f sock.php
Received HTTP/1.0 200 OK
Cache-Control: private, max-age=0
Date: Mon, 23 Feb 2009 02:57:18 GMT
Expires: -1
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie: PREF=ID=c9a669240fbcea34:TM=1235357838:LM=1235357838:S=byc9eIiH5Mc4K
GQl; expires=Wed, 23-Feb-2011 02:57:18 GMT; path=/; domain=.google.com
Server: gws
X-Cache: MISS from .
Via: 1.0 .:80 (squid)
Connection: close



C:\Documents and Settings\Jack>



User is offlineProfile CardPM
+Quote Post

KuroTsuto

RE: WAMP Server & Sockets

25 Feb, 2009 - 12:44 PM
Post #9

D.I.C Head
Group Icon

Joined: 13 Feb, 2009
Posts: 104



Thanked: 12 times
Dream Kudos: 25
My Contributions
Thanks for the long and detailed reply wink2.gif. Unfortunately, to quote my original post,
QUOTE
I have tried manually setting both of the php.ini files that appear in a WAMP install (php.ini and phpForApache.ini), yet neither seem to yield different results.


But what you have told does confirm that my attempts were carried out correctly... Perhaps this is some sort of incidental flaw in my environment, after all... I suppose I'll start digging, lol.

Thanks for the help!
~KuroTsuto
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 05:10PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month