Running a Python script from PHP: Difference between revisions

From LemonWiki共筆
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: Ppass the parameter from command line or file
** 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 protocol
* 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 protocol
* 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


icon_scale_pencil.png This article "Running a Python script from PHP" is still being written. If there are any incomplete parts, you are welcome to directly edit them. 這篇文章「Running a Python script from PHP」內容還在撰寫中,如果有不完整的部分,歡迎你直接動手修改


Different approaches[edit]

References[edit]