关于资源ID [英] About Resource id's

查看:73
本文介绍了关于资源ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我使用的是一个简单的php服务器,我写了一些问题

与资源ID相关。当新客户端连接到服务器

或服务器打开文件时,资源ID号正常增加,

但是当服务器关闭套接字和文件然后a新的

客户端连接或文件打开,资源ID仍然增加,而不会重置为先前已关闭的ID'。$

例如:


客户端连接到服务器... accept();

客户端fd:资源ID#1

客户端退出.... fclose / socket_close

客户端连接到服务器... accept();

客户端fd:资源ID#2

客户退出.... fclose / socket_close

....

....

....

客户端连接到服务器... accept();

客户端fd:资源ID#12456


难道不应该当第二个客户端

连接时,资源ID重置为#1?这种行为会给服务器带来问题吗?


我写了一个简单的套接字服务器和客户端来演示这个:


服务器:

----------


<?php

set_time_limit(0);


$ socket = stream_socket_server(" tcp://0.0.0.0:6000",$ errno,$ errstr);

if(!$ socket){

echo" $ errstr($ errno)< br /> \ n" ;;

} else {

while($ conn = stream_socket_accept( $ socket)){

testme();

testme();

testme();

打印(客户fd:"。$ conn。" \ n");

fclose($ conn);

echo''$ socket is resource = ''。 (is_resource($ conn)?''true'':

''false'')。" \ n";

}

fclose($ socket);

}


函数testme(){

$ fp = fopen(''testfdss '',''a'');


fclose($ fp);

echo''$ file_pointer is resource =''。 (is_resource($ p)?''true'':

''false'')。" \ n";

}

?>


客户:

---------


< ?php

set_time_limit(0);


while(true){

$ fp = fsockopen('''127.0.0.1 '',6000,$ errno,$ errstr,(浮动)1);


if(!$ fp){

print(" error( )\ n");

}


fclose($ fp);

}

?>


感谢您的帮助和对不起我的(坏)英语

Hello,

I am using a simple php server that I wrote and have some questions
related to the resource id''s. When a new client connects to the server
or the server opens a file the Resource id number increases normally,
but when the server closes the socket and the file and then a new
client connects or file opens, the Resource id still increases without
reseting to the previous closed id''s.

For example:

Client connects to the server...accept();
Client fd: Resource id #1
client quits.... fclose/socket_close
Client connects to the server...accept();
Client fd: Resource id #2
client quits.... fclose/socket_close
....
....
....
Client connects to the server...accept();
Client fd: Resource id #12456

Shouldn''t the resource id reset to #1 when the second client
connected ? Can this behaviour cause problems to the server ?

I wrote a simple socket server and client to demonstrate this:

server:
----------

<?php
set_time_limit(0);

$socket = stream_socket_server("tcp://0.0.0.0:6000", $errno, $errstr);
if (!$socket) {
echo "$errstr ($errno)<br />\n";
} else {
while ($conn = stream_socket_accept($socket)) {
testme();
testme();
testme();
print("Client fd: ".$conn." \n");
fclose($conn);
echo ''$socket is resource = '' . (is_resource($conn) ? ''true'':
''false'')."\n";
}
fclose($socket);
}

function testme() {
$fp = fopen(''testfdss'',''a'');

fclose($fp);
echo ''$file_pointer is resource = '' . (is_resource($p) ? ''true'':
''false'')."\n";
}
?>

client:
---------

<?php
set_time_limit(0);

while(true) {
$fp = fsockopen(''127.0.0.1'',6000,$errno,$errstr,(float) 1);

if (!$fp) {
print("error()\n");
}

fclose($fp);
}
?>

Thanks for your help and sorry for my (bad) english

推荐答案

socket = stream_socket_server(" tcp://0.0.0.0:6000",
socket = stream_socket_server("tcp://0.0.0.0:6000",


errno,


errstr);

if(!
errstr);
if (!


这篇关于关于资源ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆