निम्नलिखित कोड के साथ, मैं 1 अनुरोध प्राप्त कर सकते हैं और इसे लिखने:पीएचपी सॉकेट सुनना पाश
function listen()
{
// Set time limit to indefinite execution
set_time_limit (0);
// Set the ip and port we will listen on
$address = 'XX.XX.XX.XXX';
$port = XXXX;
// Create a TCP Stream socket
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
// Bind the socket to an address/port
$bind = socket_bind($sock, $address, $port);
// Start listening for connections
socket_listen($sock);
/* Accept incoming requests and handle them as child processes */
$client = socket_accept($sock);
// Read the input from the client – 1024 bytes
$input = socket_read($client, 2024);
// Strip all white spaces from input
echo $input;
// Close the master sockets
$close = socket_close($sock);
var_dump($close);
}
listen();
लेकिन यह एक बार यह 1 पैकेट प्राप्त सुन स्वचालित रूप से बंद कर दें। मुझे बाहर निकलने तक पैकेट प्राप्त करने की आवश्यकता है या किसी भी करीबी कमांड प्राप्त होता है।
इस फ़ंक्शन को लूप में बनाने के लिए ऊपर दिए गए कोड को बदलने के बारे में मुझे कैसे जाना चाहिए?
यदि मैं इस पोर्ट को डेटा गड्ढा भेजता हूं, तो मुझे एक चरित्र मिलता है तो यह कुछ भी प्रिंट करना बंद कर देता है। मुझे लगता है कि मूल पोस्टर की समस्या थी। – adrianTNT