PHP exec()花费太长时间来初始化,是否有其他选择?
问题描述:
我有一个脚本,其中的一部分运行一个命令行过程,如果直接在服务器上运行(Windows Server 2008),则需要不到一秒的时间。PHP exec()花费太长时间来初始化,是否有其他选择?
当运行它通过exec()
,passthru()
或system()
它需要超过30秒,但输出确认程序本身需要0.5秒,因为它直接在服务器上运行。
样品Exec的
shell_exec(path\to\software path\to\file -sqldata "SELECT * FROM table WHERE this = that" -f "path\to\output" -c path\to\config -e PDF -ec proof -o "Proof")
样品响应
Inspire Designer Console 10.0 SP1 Production System
Net license (192.168.20.102)
License is valid till 2017-06-30.
Opening workflow path\to\file 2.8.2016 9:01:08.412.
Status message 0881:Reading config file path\to\config.
Status message 0884:Running module Proof.
Status message 0243:ODBC Data Input: Executing: SELECT * FROM table WHERE this = that
Status message 0246:ODBC Data Input: Reading completed with 1 records (data)
Status message 0045:Data opened (duration 0:00:00.015, records 1).
Status message 0045:Data opened (duration 0:00:00.000, records 1).
Status message 0645:Job started (engine PDF, range 1-end, copies 1, file path\to\output).
Warning 0062:Page Page 1 uses output name Main with different size. Using bigger.
Warning 5505:PDF: Optimization for fast web view enabled. The spooling time can grow significantly.
Status message 5506:PDF: Linearization in progress.
Status message 0003:Job finished (duration 0:00:00.234, sheets 1, sheets/min 256.41).
Complete run time: 0:00:00.483.
有没有一种可行的替代方案,或者改善exec()函数的“初始化”的时间来改善我们的网站加载时间的方式?
答
编辑:
试试这个:
Proc_Close (Proc_Open ("path\to\software --field=1 &", Array(), $field));
以前它适用评论答案:
我总是用:
system('echo . | path\to\software path\to\file ect...');
它启动速度快。
为什么多余的echo会提高性能? –
我明白这个问题不是免费的处理,但在PHP脚本中不会退出 –
不幸的是,解决方案建议不会正常运行我们的软件 – TomK89