socketsetoption php,php socket函数socket_set_option怎么用?

2849587f0b0c4c504e281be893cc689a.png

慕容森

php函数bool socket_set_option ( resource $socket , int $level , int $optname , mixed $optval )用法说明:The socket_set_option() function sets the option specified by the optname parameter, at the specified protocollevel, to the value pointed to by the optval parameter for the socket。参数说明:socketA valid socket resource created with socket_create() or socket_accept().levelThe level parameter specifies the protocol level at which the option resides. For example, to retrieve options at the socket level, a level parameter of SOL_SOCKET would be used. Other levels, such as TCP, can be used by specifying the protocol number of that level. Protocol numbers can be found by using thegetprotobyname() function.optnameThe available socket options are the same as those for the socket_get_option() function.optvalThe option value.返回值:成功时返回 TRUE, 或者在失败时返回 FALSE。例子:<?php $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);if (!is_resource($socket)) {echo 'Unable to create socket: '. socket_strerror(socket_last_error()) . PHP_EOL;}if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) {echo 'Unable to set option on socket: '. socket_strerror(socket_last_error()) . PHP_EOL;}if (!socket_bind($socket, '127.0.0.1', 1223)) {echo 'Unable to bind socket: '. socket_strerror(socket_last_error()) . PHP_EOL;}$rval = socket_get_option($socket, SOL_SOCKET, SO_REUSEADDR);if ($rval === false) {echo 'Unable to get socket option: '. socket_strerror(socket_last_error()) . PHP_EOL;} else if ($rval !== 0) {echo 'SO_REUSEADDR is set on socket !' . PHP_EOL;}?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值