Last active
November 9, 2024 00:22
-
-
Save donald95/3b51ac8efa57a3aff039ce3ccc8e4cc6 to your computer and use it in GitHub Desktop.
Execute command using Process class in Laravel and Symfony
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| public function processMatchSearch(Request $request): JsonResponse | |
| { | |
| $command = 'python3'; | |
| $scriptPath = base_path() . '/scripts/research_matching_script.py'; | |
| $parameterOne = $request->input('title'); | |
| $parameterTwo = Auth::id(); | |
| $process = new Process([ | |
| $command, $scriptPath, $parameterOne, $parameterTwo | |
| ]); | |
| $process->setTimeout(6); | |
| $process->run(); | |
| if (!$process->isSuccessful()) { | |
| throw new ProcessFailedException($process); | |
| } | |
| $data = json_decode($process->getOutput()); | |
| return response()->json(['error' => false, 'data' => $data]); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment