我为我们的webservices(一个zf2 rest应用程序)创建了一个简单的脚本,它将接收一个带有params的post请求,要求脚本通过PHP exec()调用C程序和这些params以便通过调制解调器发送短信并返回json响应success = true;
<?php
$phoneNumber = "5145551234";
$message = "Sample sms text";
$smsAgentPath = "C:\installpath\smsagent.exe"; //install path to smsAgent
$optionA = 40; //Request Type (int)
$optionB = $phoneNumber; //Cellphone number to send the SMS to
$optionC = 1; //Auto update flag 1 = true
$optionD = 1; //Confirm delivery flag 1 = true;
$optionE = strlen($message); //Length of the message
$optionF = $message; //Message to send
$optionG = 1; //Message delivery request reference number
$cmd = $smsAgentPath . " [A:" . $optionA . "][B:" . $optionB . "][C:" . $optionC . "][D:" . $optionD . "][E:" . $optionE . "][F:" . $optionF . "][G:" . $optionG . "]";
$out = exec($cmd);
此脚本在easyPHP上运行完美,并按预期发送和短信给定的数字。但是一旦进入ZF2,在zend服务器上安装,所有最新的稳定版本,页面都会等待localhost响应,并在30秒或更长时间后启动空文件下载。
阅读网页,发现有关php.ini disable_functions,字符串在zend server config中是空的,也发现有关apache safe_mode,在zend服务器上的apache config及其php.ini中找不到任何提及它。将safe_mode = Off添加到php.ini并没有改变任何东西。
我错过了什么吗?
<?php
namespace Sms\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
use BaseApi\V1\Model\Log;
use Sms\Model\SmsBase;
class SendController extends AbstractRestfulController
{
protected $smsTable;
protected $logTable;
public function create()
{
$phoneNumber = "5145551234";
$message = "Sample message";
$smsAgentPath = "C:\\installpath\\smsagent.exe";
$optionA = 40;
$optionB = trim($phoneNumber);
$optionC = 1;
$optionD = 1;
$optionE = strlen($message);
$optionF = $message;
$optionG = 1;
$cmd = $smsAgentPath . " [A:" . $optionA . "][B:" . $optionB . "][C:" . $optionC . "][D:" . $optionD . "][E:" . $optionE . "][F:" . $optionF . "][G:" . $optionG . "]";
exec($cmd);
return new JsonModel(array('success' => true, 'cmd' => $cmd));
}
}
答案 0 :(得分:0)
经过8个多小时后,原来是因为zend Server将Apache作为服务启动。停止服务,手动启动Apache,并在Windows启动时,php exec将工作...