parallel/src/Threading/Thread.php

37 lines
648 B
PHP
Raw Normal View History

2015-07-13 17:30:59 -05:00
<?php
namespace Icicle\Concurrent\Threading;
class Thread extends \Thread
{
const MSG_DONE = 1;
const MSG_ERROR = 2;
private $socket;
private $class;
public function __construct($class)
{
$this->class = $class;
}
2015-07-13 17:30:59 -05:00
public function initialize($socket)
{
$this->socket = $socket;
}
public function run()
{
$class = $this->class;
$instance = new $class();
$instance->run();
2015-07-13 17:30:59 -05:00
$this->sendMessage(self::MSG_DONE);
fclose($this->socket);
}
private function sendMessage($message)
{
fwrite($this->socket, chr($message));
}
}