My existing Laravel project is such that all the tasks are executed sequentially. I have identified part of the code which can be run in parallel using PHP
threads and can reduce the response time.
Instead of using pthreads
, there was suggestion given that why not use appserver.io - which is fully multithreaded php
server itself. One can use its MessageQueue
feature, add all your job to this queue, and it will automatically fork worker threads. You don't have to manage anything.
I have already deployed existing Laravel app on appserver.io (copied project under /opt/appserver/webapps/
folder) but now I don't know how to use appserver's MessageQueue
. My project uses psr-4
, where as appserver is psr-0
. Laravel has it's own DI and so does appserver.
All I want to do is, use appserver's MessageQueue
to get more workers executing one function in parallel. I'm new to appserver and not sure how the directory structure should look like or what configuration I have do it. Any pointers will be helpful.
you can connect and send to the MessageQueue
from within your Laravel application. First you've to install the client library appserver-io/messaging
by adding "appserver-io/messaging" : "~1.0
" to your composer.json. Then you can send a message with
$queue = MessageQueue::createQueue('pms/myQueue');
$connection = QueueConnectionFactory::createQueueConnection('my-laravel-app');
$session = $connection->createQueueSession();
$sender = $session->createSender($queue);
$sender->send(new StringMessage('Some String'));
assuming you've an application named my-laravel-app
, that resides in the folder /opt/appserver/webapps/my-laravel-app
and a MessageQueue
called pms/myQueue
, defined in a file META-INF/message-queues.xml
. The file would look like
<?xml version="1.0" encoding="UTF-8"?>
<message-queues xmlns="http://www.appserver.io/appserver">
<message-queue type="MyReceiverClass">
<destination>pms/myQueue</destination>
</message-queue>
</message-queues>
In that example, the receiver class MyReceiverClass
has to be available under /opt/appserver/webapps/my-laravel-app/META-INF/classes/MyLaravelApp/Receivers/MyReceiverClass
for example.
A good start is the example application that comes with simple MessageQueue
example running some simple import functionality.