Socket programming error
When I am running my program of socket I am getting an error:
Fatal error: Call to undefined function socket_create() in C:\wamp\www\sockert\s开发者_StackOverflowockert.php on line 11
What about that error?
Code:
// set some variables
$host = "192.168.1.99";
$port = 1234;
// don't timeout!
set_time_limit(0);
// create socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
I am using php5.3.0
The sockets
extension is not activated.
You should load php_sockets.dll
in php.ini.
In the file php.ini
file, find the line with php_sockets.dll
and remove the leading semi colon (;
)
The functions staring with socket_
are not activated by default in PHP. But there exists a better alternative anyways: the stream
extension offers support for sockets too, and this is available regardless of your PHP and platform, and is also much more easy to use.
I've written a blog post explaining Stream Sockets here: http://www.christophh.net/2012/07/24/php-socket-programming/
I hope this helps.
精彩评论