Home > php教程 > php手册 > PHP不支持socket_connect函数开启步骤

PHP不支持socket_connect函数开启步骤

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-25 16:38:27
Original
1914 people have browsed it

socket_connect函数在php默认安装是不给支持的,如果要使用它我们需要在php.ini中进行简单的开启,下面我们一起来看看吧.

linux系统中开启socket_connect方法

#cd /home/php/ext/sockets #/server/php/bin/phpize #./configure --prefix=/usr/local/php/lib --with-php-config=/server/php/bin/php-config --enable-sockets #make #make install

再修改/usr/local/php/etc/php.ini文件

#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/" (php5.4版本以上不用加扩展路径) extension=sockets.so

windows系统开启socket_connect步骤:

直接修改php.ini 文件,去掉extension=PHP_sockets.dll 前面的分号,最后重启一下你的服务器环境就可以了,如iis apache nginx都可以正常使用socket_connect函数.

socket_connect说明:

bool socket_connect ( resource $socket , string $address [, int $port = 0 ] )

成功时返回 TRUE,或者在失败时返回 FALSE,代码如下:

<?php  
$address = gethostbyname ($ip);  
$command = "ping -c 1 " . $address;   
$r = exec($command);   
if ($r[0]=="r")  
{ 
    $socket = socket_create (AF_INET, SOCK_STREAM, 0);  
if ($socket < 0) {
    echo "socket_create() failed: reason: " . socket_strerror ($socket) . "\n";  
} else {  
    echo "OK.\n";  
}
Copy after login


文章地址:

转载随意^^请带上本文地址!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template