1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Rakshitbharat\Queuefy; |
5
|
|
|
|
6
|
|
|
use Illuminate\Console\Command; |
7
|
|
|
|
8
|
|
|
class ConsoleCommand extends Command |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* The name and signature of the console command. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $signature = 'queuefy:run'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The console command description. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $description = 'Run queue from console.'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Create a new command instance. |
26
|
|
|
* |
27
|
|
|
* @return void |
|
|
|
|
28
|
|
|
*/ |
29
|
|
|
public function __construct() |
30
|
|
|
{ |
31
|
|
|
parent::__construct(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Execute the console command. |
36
|
|
|
* |
37
|
|
|
* @return mixed |
38
|
|
|
*/ |
39
|
|
|
public function handle() |
40
|
|
|
{ |
41
|
|
|
$commandToExecute = ""; |
42
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
43
|
|
|
$phpPath = exec("where php"); |
44
|
|
|
$command = "tasklist | FIND "; |
45
|
|
|
} else { |
46
|
|
|
$phpPath = exec("which php"); |
47
|
|
|
$command = "pgrep "; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
if ( |
52
|
|
|
empty(config('queuefy.QUEUE_COMMAND_FULL_PATH')) |
53
|
|
|
and |
54
|
|
|
!empty(config('queuefy.QUEUE_COMMAND_AFTER_PHP_ARTISAN')) |
55
|
|
|
) { |
56
|
|
|
$commandToExecute .= $phpPath . ' '; |
57
|
|
|
$commandToExecute .= base_path() . DIRECTORY_SEPARATOR . "artisan "; |
58
|
|
|
$commandToExecute .= config('queuefy.QUEUE_COMMAND_AFTER_PHP_ARTISAN'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if ( |
62
|
|
|
!empty(config('queuefy.QUEUE_COMMAND_FULL_PATH')) |
63
|
|
|
and |
64
|
|
|
empty(config('queuefy.QUEUE_COMMAND_AFTER_PHP_ARTISAN')) |
65
|
|
|
) { |
66
|
|
|
$commandToExecute .= config('queuefy.QUEUE_COMMAND_FULL_PATH'); |
67
|
|
|
} |
68
|
|
|
$OUTPUT_FINAL = 'Nothing Done'; |
69
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
70
|
|
|
$commandToCheckProcess = $command . '"' . $commandToExecute . '"'; |
71
|
|
|
} else { |
72
|
|
|
$commandToCheckProcess = $command . '"' . $commandToExecute . '"'; |
73
|
|
|
} |
74
|
|
|
if (!($ID = shell_exec($commandToCheckProcess))) { |
75
|
|
|
$ID = trim($ID); |
76
|
|
|
$OUTPUT_FINAL = 'Process is running with PID ' . $ID . '.'; |
77
|
|
|
} |
78
|
|
|
if(empty($ID)){ |
79
|
|
|
$OUTPUT_FINAL = shell_exec($commandToExecute); |
80
|
|
|
} |
81
|
|
|
echo $OUTPUT_FINAL; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.