0

I am creating an API in PHP which pass some parameters to python and generate a report in pdf format. in report_gen.py file I have code to get parameters and generate pdf. Which is working successfully through command line but when I run PHP file from browser or postman it do not works. I want to run my PHP file through cronjob so it automatically call in specific time.

$data = 'Basic Will Johnyy Willson Smith';

$command = escapeshellcmd("python3 report_gen.py $data");

$output = shell_exec($command); echo $output;

1 Answer 1

0

There can be (at least) two problems.

First you need to check/know, that the server maid use another environment. I believe, that you did not use the webserver-user for your local checks. So I would try to use absolute pathes. You also have to make sure, that the python-environment (whatever you have configured) has to be the same as your local user.

Second you need to make sure, that you have all rights to run the file (the webserver, that is used by the webserver needs to have at least reading right on report_gen.py).

Sign up to request clarification or add additional context in comments.

4 Comments

report_gen.py have permission 644. And how to use webserver-user with absolute paths. Any syntax.
absolute pathes: Windows: "C.\\python\\python.exe C:\\bla\\fasel\\blub\\report_gen.py", Linux: "/usr/bin/python /bla/fasel/blub/report_gen.py"
I tried with absolute path but did not work through browser. Any other solution?
Are you running on Linux? You could redirect the error-ouput (stderr) to the standard output (stdout), to see, if there is some error while runnig the command: "/usr/bin/python /bla/fasel/blub/report_gen.py 2>&1"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.