Running a Python script from PHP: Difference between revisions
Jump to navigation
Jump to search
(Created page with "Running a Python script from PHP {{Draft}} == Different approaches == * Execute the Python script from command line ** Method: Using PHP function such as [https://www.php....") |
|||
| Line 7: | Line 7: | ||
* Execute the Python script from command line | * Execute the Python script from command line | ||
** Method: Using PHP function such as [https://www.php.net/manual/en/function.exec.php exec()], [http://www.php.net/manual/en/function.system.php system()], [http://www.php.net/manual/en/function.shell-exec.php shell_exec()]<ref>[https://stackoverflow.com/questions/19735250/running-a-python-script-from-php Running a Python script from PHP - Stack Overflow]</ref> | ** Method: Using PHP function such as [https://www.php.net/manual/en/function.exec.php exec()], [http://www.php.net/manual/en/function.system.php system()], [http://www.php.net/manual/en/function.shell-exec.php shell_exec()]<ref>[https://stackoverflow.com/questions/19735250/running-a-python-script-from-php Running a Python script from PHP - Stack Overflow]</ref> | ||
** Pass parameter: | ** Pass parameter: Pass the parameter from command line or file | ||
** Possible issues: It the command line is too long, it will reach the [https://docs.microsoft.com/en-US/troubleshoot/windows-client/shell-experience/command-line-string-limitation Command prompt line string limitation]<ref>[https://stackoverflow.com/questions/3205027/maximum-length-of-command-line-string windows - Maximum Length of Command Line String - Stack Overflow]</ref>. & To avoid [https://owasp.org/www-community/attacks/Command_Injection Command Injection] using [https://www.php.net/manual/en/function.escapeshellcmd.php PHP: escapeshellcmd()]. | ** Possible issues: It the command line is too long, it will reach the [https://docs.microsoft.com/en-US/troubleshoot/windows-client/shell-experience/command-line-string-limitation Command prompt line string limitation]<ref>[https://stackoverflow.com/questions/3205027/maximum-length-of-command-line-string windows - Maximum Length of Command Line String - Stack Overflow]</ref>. & To avoid [https://owasp.org/www-community/attacks/Command_Injection Command Injection] using [https://www.php.net/manual/en/function.escapeshellcmd.php PHP: escapeshellcmd()]. | ||
* HTTP GET | * HTTP GET request | ||
** Method: Using PHP function such as [https://www.php.net/manual/en/function.file-get-contents.php file_get_contents()] or PHP cUrl library [https://www.php.net/manual/en/book.curl.php Client URL Library] | ** Method: Using PHP function such as [https://www.php.net/manual/en/function.file-get-contents.php file_get_contents()] or PHP cUrl library [https://www.php.net/manual/en/book.curl.php Client URL Library] | ||
** Pass parameter: GET parameter | ** Pass parameter: GET parameter | ||
** Possible issues: Maximum length of HTTP GET request<ref>[https://helpx.adobe.com/mt/experience-manager/scene7/kb/base/is_protocol-_-forming_is/url-character-limit-get-requests.html URL character limit for Get requests | Scene7]</ref> | ** Possible issues: Maximum length of HTTP GET request<ref>[https://helpx.adobe.com/mt/experience-manager/scene7/kb/base/is_protocol-_-forming_is/url-character-limit-get-requests.html URL character limit for Get requests | Scene7]</ref> | ||
* HTTP POST | * HTTP POST request | ||
** Method: Using PHP function such as [https://www.php.net/manual/en/function.file-get-contents.php file_get_contents()]<ref>[https://stackoverflow.com/questions/2445276/how-to-post-data-in-php-using-file-get-contents http - How to post data in PHP using file_get_contents? - Stack Overflow]</ref> or PHP cUrl library [https://www.php.net/manual/en/book.curl.php Client URL Library] | ** Method: Using PHP function such as [https://www.php.net/manual/en/function.file-get-contents.php file_get_contents()]<ref>[https://stackoverflow.com/questions/2445276/how-to-post-data-in-php-using-file-get-contents http - How to post data in PHP using file_get_contents? - Stack Overflow]</ref> or PHP cUrl library [https://www.php.net/manual/en/book.curl.php Client URL Library] | ||
** Pass parameter: POST form data or payload | ** Pass parameter: POST form data or payload | ||
Latest revision as of 21:57, 20 June 2021
Running a Python script from PHP
Different approaches[edit]
- Execute the Python script from command line
- Method: Using PHP function such as exec(), system(), shell_exec()[1]
- Pass parameter: Pass the parameter from command line or file
- Possible issues: It the command line is too long, it will reach the Command prompt line string limitation[2]. & To avoid Command Injection using PHP: escapeshellcmd().
- HTTP GET request
- Method: Using PHP function such as file_get_contents() or PHP cUrl library Client URL Library
- Pass parameter: GET parameter
- Possible issues: Maximum length of HTTP GET request[3]
- HTTP POST request
- Method: Using PHP function such as file_get_contents()[4] or PHP cUrl library Client URL Library
- Pass parameter: POST form data or payload
- Possible issues: