如何在php套接字中连续运行server.php

时间:2019-04-12 06:26:11

标签: php version php-socket

整体代码可以正常工作,但是问题是我需要每次都刷新await才能工作整个代码。我如何使服务器连续运行而又没有刷新server.php的麻烦?

Client.php

server.php

Server.php

<?php
$host    = "localhost";
$port    = 1024;
$message = "Hello Server";
echo "Message To server :".$message;
// create socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
// connect to server
$result = socket_connect($socket, $host, $port) or die("Could not connect to  server\n");  
// send string to server
socket_write($socket, $message, strlen($message)) or die("Could not send data to server\n");
// get server response
$result = socket_read ($socket, 1024) or die("Could not read server response\n");
echo "<br>"."Reply From Server  :".$result;
// close socket
socket_close($socket) ?>

1 个答案:

答案 0 :(得分:0)

元刷新。我知道您可以设置间隔。即使是一秒钟或一毫秒也可能导致延迟,第二种选择也可能会流式传输。.dotnet的流式传输类编写得很好。