Php系统()挂起


Php system() hangs?

我有一个程序,其中:

  • 在php中运行无限循环,在其中我获得要处理的新记录,保存在文件中
  • 在池中脚本处理此记录的位置运行python脚本

php代码:

while(true) {
    $records = get_records();
    file_put_contents($file_name, json_encode($records));
    echo "php:system:before";
    system("python script.py $file_name");
    echo "php:system:before";
}

python代码:

import json
import os
import sys
import time
import random
import urllib2
from multiprocessing import Pool, freeze_support
from subprocess import Popen, PIPE
from os.path import isdir
from platform import system
from lib import Logger
def do_something(record):
    # ... some operations
    print("python:record:done")
if __name__ == '__main__':
    records = read_records
    pool = Pool(4)
    pool.map(do_something, records)
    pool.close()
    pool.join()
    print("python:done")

但这个过程时不时地会挂起。

我的日志:

php:system:start
python:record:done
python:record:done
python:record:done
python:record:done
python:record:done
python:record:done
python:record:done
python:done
<- here I expect php:system:before

但一天两次我都没拿到,我重新设置了程序。错误在哪里,为什么脚本挂起?

这是Apache中的一个已知错误:

https://bugs.php.net/bug.php?id=44942