batch - multi threading artisan servers - php

The question is straight forward, how can I run two php artisan commands at the same time?
I have two commands:
php artisan serve --host=0.0.0.0 --port=80
and
php artisan queue:work --queue=high,default
If I run them in seperated cmd windows, it works, but I would like to have them in just one cmd window.
Is this possible? I currently have this code:
#ECHO OFF
ECHO Starting DigiCoach Application
TITLE Digicoach Console application
ECHO This might take a while...
CMD /T:70 /b php artisan serve --host=0.0.0.0 --port=80
CMD /T:70 /b php artisan queue:work --queue=high,default

If you start them they will run in parralel:
Start "" php artisan serve --host=0.0.0.0 --port=80
Start "" php artisan queue:work --queue=high,default
Edit. As per #Aacini's comment the /b switch might be useful to what you require as it starts both commands without opening a new window.
Start /b "" php artisan serve --host=0.0.0.0 --port=80
Start /b "" php artisan queue:work --queue=high,default
I would however not recommend this as the output will not be what you expect. Something like calling something as simple as 2 ping commands can give an output that seems to be of an unknown language as the one commands output interferes with the others.

Related

Execute each line of bash in separate terminals

I have create a simple bash script for my laravel project (file name: bash-script.sh)
php artisan serv
php artisan queue:work --queue=first_queue
php artisan queue:work --queue=second_queue
php artisan queue:work --queue=third_queue
php artisan queue:work --queue=fourth_queue
php artisan schedule:work
the problem is I want each line of these commands to run in separate terminals.
Maybe this can help you, in the same terminal all processes responses:
php artisan serv &
php artisan queue:work --queue=first_queue &
php artisan queue:work --queue=second_queue &
php artisan queue:work --queue=third_queue &
php artisan queue:work --queue=fourth_queue &
php artisan schedule:work
The ampersand (&) it's for executing in another process and freeing the current execution, all outputs in every processes will write on the same terminal
Or if you do not have a graphic environment on the host (ie you connect to the remote host via ssh) you need a terminal multiplexer like screen or tmux
For both, there are several howto and example all over the web
If you want them to run in a terminal window, you will have to start a terminal window.
xterm -e "php artisan serv"&
xterm -e "php artisan queue:work --queue=first_queue"&
xterm -e "php artisan queue:work --queue=second_queue"&
# et cetera

Can i run multiple command with artisan serve laravel?

Is it possible to run some other arrtisan command when we run php artisan serve . at the same time ? Is there any way to do that?
You can run multiple commands separated by a semi-colon.
For example:
php artisan view:clear; php artisan route:clear; php artisan cache:clear; php artisan config:clear
Would that help?
You need to setup supervisor on the server. It will start the queue:work for you. It can also run multiple executions of same commands.

Docker running a command on container start up

I have a docker container, for which I need to run the following command
php /var/www/html/artisan queue:work &
It starts a worker process that looks for jobs and executes them.
I can run it by doing exec -it when the container is running.
But I need to do it using Dockerfile so that when my container re-deploys, it starts this automatically. I have tried
RUN php /var/www/html/artisan queue:work
CMD ["php","/var/www/html/artisan","queue:work"]
ENTRYPOINT ["php","/var/www/html/artisan","queue:work"]
separately of course. but none of them work. In the case of CMD and ENTRYPOINT my container starts giving out a 502 error and my service becomes inaccessible.
What am I doing wrong?
You could do this in multiple ways.
You could write a shell script that starts the background process first and then starts your API.
CMD ["./start_server.sh"]
Contents of ./start_server.sh
#!/bin/bash
php /var/www/html/artisan queue:work &
exec php-server-serving-api
You could also do this through a docker entrypoint shell script
ENTRYPOINT ["./docker-entrypoint.sh"]
CMD ["php-server-serving-api"]
Contents of ./docker-entrypoint.sh
#!/bin/bash
php /var/www/html/artisan queue:work &
exec $#
However, what I recommend is, if they are separate type of workloads, run them in separate container. If the background processing task crashes, there is no one to restart it. If you run it as a separate container, you could use a system to restart it.

Artisan make:controller Doesn't work and no error

I'm using Laravel 5.3.0 and it's running on a local server with Manjaro. I access the project folder trough ssh and I'm also using artisan trough SSH.
Everything runs fine, I run the server trough terminal:
php artisan serve --host 192.168.0.10 --port 80
And can acess the project trough browser.
But when I run this command:
php artisan make:controller ContatoController
or
artisan make:controller ContatoController
Nothing happens, it get's stuck, no message error after minutes. No controller is created.
Does anyone know how to solve this?
Here's what happened:
I was running artisan server and after that (on the same terminal) I was running the make:controller command.
The solution was:
1- Open linux terminal, run artisan server;
2- Open another terminal (or split window if you'r using Terminator) and use all commands you want.

How do I remove old artisan command from Kernel in Laravel 5

I have created some Command files into my Laravel Application. Laravel version is 5.2. I set command like: get:email in the Command file. Also call the Command file into Kernel.php. After that I can see the artisan command list by typing the command php artisan list. as like as below:
//output
get:email
And I changed the command title get:email to get-bq:email. When I run the command php artisan get-bq:email -- its working nicely. Also I can see the list by typing the command php artisan list::
//output
get-bq:email
Issue / Problem: Both commands are working. But I won't to work with both of them. I have done the following things:
modified command file as well as command
run composer dump-autoload -o
run composer update
remove vendor and storage folder then run composer update again.
Still the old command is working into my system.
What I want: How May I remove my old commands from my Laravel(5.2) application?
Run these commands:
php artisan cache:clear
php artisan config:clear
These commands will clear app cache and config cache and recreate it.
I've had the same problem recently.
Repoeatedly tried
php artisan cache:clear
php artisan config:clear
and the cached Kernal command wouldn't clear.
In desperation i killed the queue worker terminal and restarted the queue with the command
php artisan queue:work
The issue stopped.

Categories