그래서 내가 스레드를 만들고 주 프로세스에서 분리하고 시작한다고 가정 해 봅시다.PHP에서 실행중인 스레드에 데이터를 전달하는 방법은 무엇입니까?
따라서 스레드가 분리 된 후에 이미 실행중인 스레드에 strings
또는 int
과 같은 데이터 청크를 전달할 수 있습니까?
편집 내가 기본적으로 WS 프로토콜을 구현하기 위해 노력하고있는 중이 야 : 나는 실행중인 스레드에 데이터를 전달 관련된 다양한 답을 찾을
<?php
// Pseudo-Code
class LongRunningThread extends \Thread {
private $handshakeReq;
public function __construct(Request $handshakeRequest) {
$this->handshakeReq = $handshakeRequest;
}
public function run() {
// Do handshake
// But do not exit, because after the handshake is done the socket connection needs to be maintained.
// Probably some trigger which notifies that a new message is here and the message arrives <automagically>
if(trigger) {
$message = $message;
$this->onNewWsMessage($message);
}
}
public function onNewWsMessage(string $rawMessage) {
// Process the message...
}
}
$stream = stream_socket_server(sprintf("tcp://%s:%d",
"localhost",
1337
), $errno, $errmsg);
// Boiler plate, and connection acceptance (blah blah blah)
// $client is the the accepted connection
$message = fread($client, 4096);
// Cannot pass the $client in here because the instability of resources with threads
// as passing them here, apparently converts them to <bool> false
$longRunningThread = new \LongRunningThread($message);
$longRunningThread->start() && $longRunningThread->join();
을하지만 구체적으로 어떤을 찾을 수 없습니다 PHP
. 내가 pthreads
거기에 코드를 추가했습니다. 당신은 대답에 주어진 링크에 대해 약간의 것들을 설명합니다 =) – Ikari