I created a simple client server codes in PHP and I run it through Wamp server localhost in browser. It works but when I run it in cmd, the output looks like this :
c:\wamp\www\Converter>php testserver.php
PHP Fatal error: Call to undefined function socket_create() in C:\wamp\www\Converter\testserver.php on line 15
PHP Stack trace:
PHP 1. {main}() C:\wamp\www\Converter\testserver.php:0
Fatal error: Call to undefined function socket_create() in C:\wamp\www\Converter\testserver.php on line 15
Call Stack:
0.0005 248032 1. {main}() C:\wamp\www\Converter\testserver.php:0
c:\wamp\www\Converter>php ex3_server.php
PHP Fatal error: Call to undefined function socket_create() in C:\wamp\www\Converter\ex3_server.php on line 5
PHP Stack trace:
PHP 1. {main}() C:\wamp\www\Converter\ex3_server.php:0
Fatal error: Call to undefined function socket_create() in C:\wamp\www\Converter\ex3_server.php on line 5
Call Stack:
0.0002 232968 1. {main}() C:\wamp\www\Converter\ex3_server.php:0`
Why does this happen? Do I need to edit any settings in windows? It seems to work through browser but I need to run server through cmd to see stats. My server code is as follow :
<?php
//server_side
$address="localhost";//your ip
$port="10012";//port number
$socket=socket_create(AF_INET,SOCK_STREAM,0);
if($socket)
echo "<br>Successfully socket created<br>";
else
echo "<br>Cannot create socket<br>";
$bind=socket_bind($socket,$address,$port);
if($bind)
echo "<br>Successfully binded to socket<br>";
else
echo "<br>Cannot bind socket<br>";
//listens for a connection on a socket
$listen=socket_listen($socket) or die ("could not setup");
if($listen)
echo "<br>Successfully listen connection<br>";
else
echo "<br>Cannot listen connection<br>";
//accepts a connection on a socket
$accept=socket_accept($socket) or die ("could not accept");
if($accept)
echo "<br>Successfully accepted request<br>";
else
echo "<br>Connot accept request<br>";
//send message 1
$message1="Hello Client";
$write=socket_write($accept,$message1);
//read reply2
$read2=trim(socket_read($socket,1024));
echo $read2."
";
?>