Running Artisan commands

anand_aks

Member
Using ExeOutput for PHP 2021 with a Laravel app that requires both queue workers and websockets.
In local dev, I run:

php artisan queue:work
php artisan websockets:serve

Inside the compiled EXE, I can’t run these manually.
What’s the best way to have both commands start automatically when the EXE launches?
 
No Laravel expert here, but maybe this would work:

Hook into the onStartMainWindow event and execute a custom PHP script:
Code:
// onStartMainWindow HEScript
procedure OnStartMainWindow;
begin
  RunPHP('startup.php');
end;

Then in startup.php:
Code:
<?php
// Set up argv for Artisan
$_SERVER['argv'] = ['artisan', 'queue:work'];
include('artisan');

// Run websockets in parallel (if supported)
$_SERVER['argv'] = ['artisan', 'websockets:serve'];
include('artisan');
?>

Another option to try if above does not wrok for you is shell_exec:
Code:
<?php
shell_exec("start /B php artisan queue:work");
shell_exec("start /B php artisan websockets:serve");
?>

Again, no Laravel expert and just started learning Larvavel.
 
I tried the below code inside Application settings > scripting > User main
PHP:
procedure OnStartMainWindow;
begin
  RunPHP('startup.php');
end;

But getting Syntax error
Sorry about that. Not in my home office and no access to exeout. I provided the code from my memory and it appears my memory and code are wrong.

I will be back on Aug 14 and can take a better look. Hopefully @gdgsupport will checkin before that and assist you.
 
Thanks for the reply. @gdgsupport @oldteacher

But I am still having issues

Can you explain in more detail how to implement my requirement using the standalone artisan.exe you mentioned?


I am currently using ExeOutput 2021, but I think the standalone Artisan support is only available in ExeOutput 2024.


What I want is: when the user opens the main application, it should automatically run the Laravel queue:work command in the background.


How can I achieve this using the standalone Artisan?
 
The sole way is described here:
 
@gdgsupport I have tried many ways to run artisan exe using application still no success. Is there any better documentation or video explaining how to do this. I have downloaded the sample Laravel from website and got a laravel-artisan.exop also. Tried to run that but it open command promt and it close suddenly. Do I need to configure anything else to run that with an artisan command.
 
The laravel-artisan.exop package allows you to build a standalone Artisan console application. Once you have created the executable, simply place the .exe file in your Laravel application directory. Then, open a command prompt and you will be able to run Artisan commands directly from it.

First, try this approach and make sure it works for you. Once confirmed, we can move on to the next step: running these commands from your application by calling the executable using HEScript.
 
@gdgsupport Thats for the response. So I generated artisan.exe from the laravel-artisan.exop package then placed it in my laravel project. After that cmd to that folder and running an artisan command work. The service did gets started. As a next step you mentioned to call it via HEScript.


I added
procedure RunArtisan;
var
EbookPath, MyProgram: String;
begin
EbookPath := GetGlobalVar("HEPublicationPath", "");
MyProgram := EbookPath + "artisan.exe";
RunAProgram(MyProgram, "", EbookPath, false, SW_SHOWNORMAL);
end;

inside UserMain. I tried called it via php / javascript but it did do the trick.

I need to pass an artisan command like "queue:work" also. How can I pass artisan command and call it when application starts
 
Last edited:
To pass commands you should change the 2nd parameter in RunAProgram:

Code:
procedure RunArtisan;
var
EbookPath, MyProgram: String;

begin
EbookPath := GetGlobalVar("HEPublicationPath", "");
MyProgram := EbookPath + "artisan.exe";
RunAProgram(MyProgram, "queue:work", EbookPath, false, SW_SHOWNORMAL);
end;

Then, to invoke this command at startup, still in UserMain script, locate
procedure OnStartMainWindow;

and change it to something like:

Code:
procedure OnStartMainWindow;
begin
  RunArtisan;
end;

Ensure the procedure RunArtisan; code is above OnStartMainWindow so that it can be found by the script engine.
 
@gdgsupport
Thanks for the reply. I followed the steps as described above. I added artisan.exe to the same folder where the main .exe is located, then added the RunArtisan function at the top of UserMain, and called it inside the OnStartMainWindow procedure.


When the application starts, the .exe runs and shows the message:


“This application was built with ExeOutput for PHP TRIAL available at http://www.exeoutput.com
REDISTRIBUTION IS PROHIBITED: PURCHASE A LICENSE.”

I understand this message appears because the license has not been added yet, and I will resolve that later.


The current issue is that the passed parameters are not being executed. The command prompt opens, but it just stays there and does not run the provided parameters.

Few test I done : artisan.exe queue:listen
Result : Could not open input file :artisan

artisan.exe queue:env , This will run correctly
 
Last edited:
When I try manually it is running, But when the parameter is passing and calling using RunAProgram, the cmd will open an show the msg

“This application was built with ExeOutput for PHP TRIAL available at http://www.exeoutput.com
REDISTRIBUTION IS PROHIBITED: PURCHASE A LICENSE.”

And it will stay like that. No Artisan command started or any error msg came there. Like it stuck after showing the msg
 
Back
Top