dtqpw68806 2015-09-17 16:53
浏览 68

PHP fputs“等待”直到脚本结束

Currently I am trying to develop a PHP script used as a publicly available part of a client/server application. The php script should be used to authenticate users with a one-time token.

The other part of the application is a java program, which offers a telnet socket for other applications to connect to. Authentication is done through this telnet connection.

The java part is already working - but I still have a huge problem with the PHP part.

In php, I have opened a connection to the telnet port of the java program, which works so far. After the connection is initialized, the java program waits for input from the PHP script in order to authenticate the user.
After the authentication process has been finished, it returns a String to the PHP script (or any other program connected to its telnet server) which the PHP script should output.

Before I explain my problem, this is the part of the PHP script where the actual communication happens:

$tnconn = fsockopen("localhost", 53135, $errno, $errstr, 2);

if(!$tnconn) {
} else {
    $data = $p_ip." ".$p_name." ".$p_token;
    fputs($tnconn, $data);

    while (true) {
        if(($telnet_response = fgets($tnconn)) == false) {

echo $telnet_response;

It seems like the fputs() statement is executed after the loop even tho it should happen before it starts - else the java application couldn't get the data that is passed to the php script, but it is needed to authenticate users.

Right after the data was received, the telnet server would output the String to indicate whether authentication was successful or not.

I tried temporarily removing the loop and the data was successfully passed with fputs() so I assume php waits until the whole script is finished and then executes the function.

How can I make it send the data before the loop?

Thank you in advance.

  • 写回答



      相关推荐 更多相似问题


      • ¥15 在线教育培训平台,主要以点播视频和在线练习测试为主,除将视频做切片外,有其他哪种方式降低流量?(关键词-带宽速率)
      • ¥20 用c语音或c++实现银行叫号系统
      • ¥15 人工智能 规则正向演绎和推理
      • ¥20 基于STM32F401的电子密码锁设计
      • ¥15 famamacbeth回归中遇到only size-1 arrays can be converted to Python scalars,求解答
      • ¥15 单片机多个自锁按键的编程实践
      • ¥15 用python操作redis存储中文后,再取出的数据变成了乱码怎么办?
      • ¥15 C语言简单排序问题有偿求解
      • ¥20 请问图片的代码什么意思
      • ¥15 coq问题求带,有偿