Skip to content

Instantly share code, notes, and snippets.

@donald95
Last active November 9, 2024 00:22
Show Gist options
  • Select an option

  • Save donald95/3b51ac8efa57a3aff039ce3ccc8e4cc6 to your computer and use it in GitHub Desktop.

Select an option

Save donald95/3b51ac8efa57a3aff039ce3ccc8e4cc6 to your computer and use it in GitHub Desktop.
Execute command using Process class in Laravel and Symfony
<?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