stream_socket_enable_crypto();禁用stream_set_timeout [英] stream_socket_enable_crypto(); Disables stream_set_timeout

查看:150
本文介绍了stream_socket_enable_crypto();禁用stream_set_timeout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个xmpp服务器,首先使用了非tls,它可以按我的要求正常工作而没有错误.漏洞认证有效,我可以毫无问题地聊天.

I have created an xmpp server, first using non tls which works as I want with no errors. The hole authentication works and I can chat with no problems.

在我开始从套接字读取之前,我做了:

Before I start reading from the socket I did:

stream_set_timeout($sock, 0, 1000); 

这将让我在服务器没有新数据的时间内做事.

This will let me do things within the time when there is no new data from the server.

现在,我实现了starttls. 我做了

Now I implemented starttls. I did

stream_socket_enable_crypto($sock, true, STREAM_CRYPTO_METHOD_TLS_SERVER);

为我协商tls.这没有用,因为发生了读取超时并且tls协商失败.

which negotates the tls for me. This didn't worked because the read timeout occured and the tls negotation failed.

我将上述 stream_socket_enable_crypto 更改为

stream_set_timeout($sock, 30, 0);
stream_socket_enable_crypto($sock, true, STREAM_CRYPTO_METHOD_TLS_SERVER);
stream_set_timeout($sock, 0, 1000);

要将超时设置得更高一些,因此客户端有30秒的时间接受证书(如果是自签名的)并完成所有tls的工作. 完成此操作后,我真的需要将超时设置回1000微秒. 更改后TLS协商有效,但是我丢失了超时设置.

To set the timeout a bit higher, so the client has 30 seconds time to accept the certificate (if self signged) and do all the tls stuff. After this is finished I really need to set the timeout back to 1000 microseconds. The TLS-Negotation worked after this change, but I lost my timeout settings.

这是我的问题. stream_socket_enable_crypto 之后的 stream_set_timeout 调用不起作用.

This is my problem. The stream_set_timeout call after stream_socket_enable_crypto does not work.

我有一个日志条目

echo "AFTER PROCESS MESSAGE QUEUE\n";
$buffer = fread($sock, 4096);
echo "AFTER SOCKET READ\n";

已打印消息 AFTER PROCESS MESSAGE QUEUE ,但是未打印 AFTER SOCKET读取,并且我等待多长时间也没有关系.

The message AFTER PROCESS MESSAGE QUEUE is printed but the AFTER SOCKET READ is not printed out and it does not matter how long I wait.

有人能用胶水将流读取超时设置回1000微秒吗?

Does anybody has a glue how I can set the stream read timeout back to 1000 microseconds?

有关您的信息: 当前需要一种我应该将stream_set_blocking设置为false的解决方案. 现在,我只想要一个阻塞的解决方案. 如果真的没有其他解决方案可以使用非阻塞,那我当然想知道:)

For your info: A solution where I should set stream_set_blocking to false is currently NOT wanted. For now I only want a blocking solution. If there is REALLY no other solution as to use non-blocking, then of course I want to know :)

推荐答案

我遇到了同样的问题. stream_select帮助我解决了问题:

I had the same problem. stream_select helped me solve the problem:

$buffer='';
$select=array('con1'=>$socket);
$timeout_sec=1;
if(stream_select($select, $null, $null, $timeout_sec)){
    $buffer = fread($socket, $size);
}

这篇关于stream_socket_enable_crypto();禁用stream_set_timeout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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