Running a Python script from PHP
Jump to navigation
Jump to search
Running a Python script from PHP
![]() |
Different approaches
- 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: