@motinska94 you may try debug like this
if (! exec('python ' . public_path('\images\users\main.py'))) {
dd('has error');
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I wrote a simple python script to run once a day and rescale-resize-optimize user pictures to optimize loadtimes. I tried to run it using exec() and shell_exec() but every single time it returns either "", [] or null.
My main.py and resize.exe files do all the work (they're same script in different formats) and I put them both in the same dir as images. Using chmod might be unnecessary, but it was the last thing I tried before running out of patience and posting here.
My Code :
chmod(public_path('\images\users\main.py'), 777);
$response = shell_exec('python ' . public_path('\images\users\main.py'));
dd($response);
returns null
chmod(public_path('\images\users\main.py'), 777);
$response = exec('python ' . public_path('\images\users\main.py'));
dd($response);
returns ""
chmod(public_path('\images\users\resize.exe'), 777);
$response = exec(public_path('\images\users\resize.exe'));
dd($response);
returns ""
I tried every combination of files and commands, with and without chmod, even tried adding sleep(2) because I thought laravel wasn't waiting for my script to finish its job (which takes less than a second).
@motinska94 i was use Intervention image package to crop / resize image, you may check it out
Please or to participate in this conversation.