Php Exec Python Script 'weakness'/downside
Solution 1:
You problem is very common - and in general it's not about executing python scripts - but to execute some external commands. To do that, you'll need some conditions to be fulfilled:
- Normally, PHP is run by web-server. So to execute some script, web-server must be able to do that. It means - that OS user, from which web-server was launched, must have enough permissions to execute external command
- In many cases, external execution functions, like
exec()
orsystem()
are treated as unsafe - and, thus, are disabled in common case (I'm speaking about hostings). So, relying on those functions will make your application's technical requirements more strict - and you'll not be able to use such hostings.
Besides described above, PHP script will "hang" until full data will be passed from exec()
back to script. That means slow execution and low-predictable response-time. And, more, in Win systems execution of external scripts is included to total script execution time (unlike in *nix systems) - and, therefore, you may have good chances to catch time limit error if your external script was too long to response.
If you want to make some "comparison" with launching python script as CGI - then you should choose CGI. At least because it's intended to serve that purpose. Launching python script with CGI will definitely win in terms of speed - because there will be no overhead for launching PHP script (and you may, for example, disable PHP support if you want to only use python). Permissions level in common case will not be a problem, since, at end point, executable will be launched from web-server user, thus, they will be same in both cases. And, as I've mentioned above, launching via CGI will not bind you to PHP's time limits - you'll not care about what's happening in PHP.
So the main idea is - yes, it is a way to launch. But no - that's not a thing that you should do if you can do that natively via CGI launch.
Post a Comment for "Php Exec Python Script 'weakness'/downside"