Home > Backend Development > PHP Tutorial > When php calls python, how to use passthru, exec, and system safely?

When php calls python, how to use passthru, exec, and system safely?

WBOY
Release: 2016-08-08 09:06:33
Original
1297 people have browsed it

There are two related questions:

1.
If you use exec, remove disable_functions.

How to ensure safety?

Second, put 1.php and test.py in the same directory
1.php:

<code><?php
   exec('python test.py');
?>
</code>
Copy after login
Copy after login

test.py:
print '1234'

Call http://localhost/1.php, no response?

Reply content:

There are two related questions:

1.
If you use exec, remove disable_functions.

How to ensure safety?

Second, put 1.php and test.py in the same directory
1.php:

<code><?php
   exec('python test.py');
?>
</code>
Copy after login
Copy after login

test.py:
print '1234'

Call http://localhost/1.php, no response?

If there is no response when calling python in php, it may be due to an environment variable problem. You can try using the absolute path of python + the absolute path of the python file to call.
If there is no special treatment, the call here may be a synchronous call of http. This place will wait for python to run and may time out.

Try to use exec and other functions in CLI mode

Directly adjust php with python

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template