2014-09-29 66 views
0

我有程序,其中:在PHPPHP系統()掛起?

  • 運行無限循環,在那裏我獲得新的記錄過程中,文件保存
  • 執行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 

但一天兩次我不明白這一點,我重置程序。 錯誤在哪裏,爲什麼腳本掛起?

回答

1

這是Apache的一個已知的bug:

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

+0

你確定這是運行Apache的背後?看起來更像是一個shell腳本/ cronjob。 – smassey 2014-09-29 08:46:55

+0

它在Windows 7上從命令行運行。 – krynio 2014-09-29 08:50:17

+0

啊好的。你爲什麼使用PHP這一點,其餘的蟒蛇?爲什麼不使用python – Bowersbros 2014-09-29 08:57:15