Added package to delegate the execution of event listeners to a swoole task worker

This commit is contained in:
Alejandro Celaya 2019-07-14 10:46:31 +02:00
parent 4380b62715
commit 0dfadcbb4a
6 changed files with 23 additions and 9 deletions

View File

@ -30,6 +30,7 @@
"mikehaertl/phpwkhtmltopdf": "^2.2",
"monolog/monolog": "^1.21",
"phly/phly-event-dispatcher": "^1.0",
"phly/phly-swoole-taskworker": "^1.1",
"shlinkio/shlink-installer": "^1.1",
"symfony/console": "^4.2",
"symfony/filesystem": "^4.2",

View File

@ -9,6 +9,11 @@ return [
'swoole-http-server' => [
'host' => '0.0.0.0',
'process-name' => 'shlink',
'options' => [
'worker_num' => 16,
'task_worker_num' => 16,
],
],
],

View File

@ -5,6 +5,7 @@ namespace Shlinkio\Shlink;
use Acelaya\ExpressiveErrorHandler;
use Phly\EventDispatcher;
use Phly\Swoole\TaskWorker;
use Zend\ConfigAggregator;
use Zend\Expressive;
@ -18,6 +19,7 @@ return (new ConfigAggregator\ConfigAggregator([
Expressive\Swoole\ConfigProvider::class,
ExpressiveErrorHandler\ConfigProvider::class,
EventDispatcher\ConfigProvider::class,
TaskWorker\ConfigProvider::class,
Common\ConfigProvider::class,
Core\ConfigProvider::class,
CLI\ConfigProvider::class,

View File

@ -3,6 +3,7 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core;
use Phly\Swoole\TaskWorker\DeferredListenerDelegator;
use Shlinkio\Shlink\Common\IpGeolocation\IpLocationResolverInterface;
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
@ -18,6 +19,11 @@ return [
'factories' => [
EventDispatcher\LocateShortUrlVisit::class => ConfigAbstractFactory::class,
],
'delegators' => [
EventDispatcher\LocateShortUrlVisit::class => [
DeferredListenerDelegator::class,
],
],
],
ConfigAbstractFactory::class => [

View File

@ -3,7 +3,9 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\EventDispatcher;
final class ShortUrlVisited
use JsonSerializable;
final class ShortUrlVisited implements JsonSerializable
{
/** @var string */
private $visitId;
@ -17,4 +19,9 @@ final class ShortUrlVisited
{
return $this->visitId;
}
public function jsonSerialize(): array
{
return ['visitId' => $this->visitId];
}
}

View File

@ -25,14 +25,7 @@ final class UnknownVisitLocation implements VisitLocationInterface
return 'Unknown';
}
/**
* Specify data which should be serialized to JSON
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize()
public function jsonSerialize(): array
{
return [
'countryCode' => 'Unknown',