php - Is it a bad idea to run a python script and fetch its output via PHP?
问题描述
I am using php to run a python script and fetching its output using json.dump and showing on my php page. I feel its slower than when I run it through python idle.
解决方案
If I understand your question correctly it's no surprise that it feels slower because calling your Python script from PHP, instead of calling it from CLI, increases the operations your PC has to execute. Consider this: first PHP has to create a shell to call your script, then wait for it to finish (e.g. wait for an exit code appearing in the buffer), grab everything from the buffer and then push it into the output buffer and then flush the output buffer, so the data is actually displayed on your page. And besides all of that your output data is transported twice, first from Python to PHP and then from PHP to your browser.
Furthermore, the processing speed depends on the method you use to call your Python script - there are a couple of ways to achieve this and some have more overhead than others.
推荐阅读
- c++ - 改变 const_cast ptr/ref 的值不会改变原始对象的值吗?
- flutter - Dart - 过滤列表中至少包含一个元素的列表
- c - 可变参数函数中的默认参数提升
- image-processing - Halcon - gen_gabor 不输出 Gabor 核的功率谱
- python - 组合来自两个不同 DataFrame 的类别代码,然后将其作为列应用到每个 DataFrame
- git - Gerrit 读取制表符,在 Vim 中使用空格
- powershell - 使用 WinSCP .NET 程序集在 FTP 服务器上生成新文件和修改文件的列表
- jenkins - Jenkins 声明性管道字符串参数和建议
- reactjs - 当用户与按钮交互时,Redux 回调函数
- mysql - 通配符 LIKE 是否比 MySQL 中的多个布尔搜索更高效?