Files
Phraseanet/lib/Alchemy/Phrasea/TaskManager/Event/PhraseanetIndexerStopperSubscriber.php
Romain Neutron 6ef6387abf Address comments
2013-10-29 18:46:36 +01:00

49 lines
1.2 KiB
PHP

<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\TaskManager\Event;
use Alchemy\TaskManager\Event\TaskManagerEvents;
use Alchemy\TaskManager\Event\JobEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PhraseanetIndexerStopperSubscriber implements EventSubscriberInterface
{
private $port;
public function __construct($port)
{
$this->port = $port;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return array(
TaskManagerEvents::STOP_REQUEST => array('onStopRequest'),
);
}
public function onStopRequest(JobEvent $event)
{
if (false !== $socket = socket_create(AF_INET, SOCK_STREAM, 0)) {
if (socket_connect($socket, '127.0.0.1', $this->port) === true) {
socket_write($socket, 'Q', 1);
socket_write($socket, "\r\n", strlen("\r\n"));
}
socket_close($socket);
}
unset($socket);
}
}