php - 无法从 php mac 执行长时间运行的 python 脚本
问题描述
我正在使用 php exec 调用 python 脚本来执行。python脚本有一个ncbiwww在线爆破方法,执行需要30多秒。我将maximum_execute_time
php.ini 中的内容编辑为 720 秒。短时间运行的 python 脚本给了我输出(我正在将输出写入一个 json 文件),长时间运行的脚本没有给我输出(没有写入文件)。我的代码如下:
爆炸.php:
if (!empty($_POST['inputFromHtml'])) {
$python = (exec("path-to-python-script/pythonScript.py &")); //**this is not executing**
$array = array('inputFromHtml' => $variable);
$fp = fopen('path-to-json-file/inputWrittenToJson.json', 'w'); //**this part works**
fwrite($fp, json_encode($array, JSON_PRETTY_PRINT));
fclose($fp);
if ($python) {
echo "Successful! <br />"; //this not executing
// echo "Accession number: " . $variable . "<br>"; //**not echoing**
echo $python; // **not outputting**
$URL = "http://localhost/folder/blast.php"; //**page refreshing but appears to be waiting for output forever**
echo "<script type='text/javascript'>window.location.href = '{$URL}';</script>";
echo '<META HTTP-EQUIV="refresh" content="0;URL=' . $URL . '">';
}
);
} elseif (alternative code) {
other methods
}
我已经搜索了几个论坛,但还没有解决方案。如果我使用终端(mac 用户),我的 python 脚本将完全执行。
我的python脚本:
import json, xmltodict, pprint, datetime, os, sys,
from flask import Flask,
from flask import request,
from Bio.Blast import NCBIWWW
with open('path-json-file-with-my-variable/inputWrittenToJson.json') as json_file:
acc_dict = json.load(json_file)
acc = acc_dict['accessionNumber']
print(acc)
result_handle = NCBIWWW.qblast("blastn", "nr", acc, format_type="XML")
data = xmltodict.parse(result_handle.read(), process_namespaces=True)
pp = pprint.PrettyPrinter(indent=4)
with open('path-to-save-blast-output/blastOutput.json', 'w') as fp:
pp.pprint(json.dump(genomeData, fp))
解决方案
推荐阅读
- mysql - Mysql:如何在 created_at 位置后 2 个月检索行
- laravel - 我想显示每个类别的所有帖子
- java - Regex to Mask all but Last Two Digits of a Number of Specific Length
- swift - 在 macOS Catalina 中拖放磁盘
- docker - Dockerfile 入口点似乎是追加而不是覆盖
- c - 如何对齐阵列以相互适应?
- google-cloud-dataflow - Splittable DoFn 导致 Shuffle key 太大的问题
- oracle - 向用户授予资源以创建表
- php - 从 JSON 编码中删除数组方括号 | PDO
- python - 有没有办法使用 pip 安装 psycopg2 而无需在主机系统上安装 postgres