Socket programming: Call to undefined function socket_create() error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeyshree
    New Member
    • Jul 2010
    • 75

    Socket programming: Call to undefined function socket_create() error

    Hai,
    I am new to php socket programming.I have a doubt.
    Code:
    <?php	if(!($sock = socket_create(AF_INET, SOCK_STREAM, 0)))
    	{
    	    $errorcode = socket_last_error();
    	    $errormsg = socket_strerror($errorcode);
    	     
    	    die("Couldn't create socket: [$errorcode] $errormsg \n");
    	}
    	 
    	echo "Socket created";
    ?>
    When i use this code,it shows an error"Fatal error: Call to undefined function socket_create() in C:\wamp\www\hai \socket.php on line 1".I am using windows 7 OS and wampserver version 2.0c.Will you please suggest me a way to solve the bug?thanks for your reply in advance.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    Looks like your server doesn't have the sockets extension enabled. You'll need to enable that to use those functions in your code. For a detailed explanation of that, see this page in the manual:

    Installation of extensions on Windows

    Comment

    • jeyshree
      New Member
      • Jul 2010
      • 75

      #3
      hai,
      found the answer.you need to enable the socket extension in wamp. Click the wamp icon in the taskbar, go to
      PHP => PHP extensions and click php_sockets. Make sure it has a tick mark to indicate that it is enabled.

      After that restart apache. Now socket functions should work fine.thanks for replying me

      Comment

      Working...