如果我通过浏览器运行页面,我有一个脚本可以完美地工作,但如果我试图将脚本设置为与Windows任务调度程序一起运行,我得到
"Fatal error: Class 'SoapClient' not found" error.
我在php.ini中启用了Soap扩展。这是我在计划任务的操作中设置的内容:
Program = D:'wamp'bin'php'php5.4.16'php.exe
Arguments = -f D:'wamp'www'Web'ScheduledTasks'Import.php
Start In = D:'wamp'www'Web'ScheduledTasks
下面是我为SoapClient使用的代码:
$Client = new SoapClient("https://www.domain.com/services/secureWebService.svc?wsdl",
array('location' => 'https://www.domain.com/services/secureWebService.svc/soap',
'cache_wsdl' => WSDL_CACHE_NONE));
AddWCFUsernameToken($Client, 'Username', 'Password');
function AddWCFUsernameToken($Client, $username, $password) {
$wssNamespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
$username = new SoapVar($username, XSD_STRING, null, null, 'Username', $wssNamespace);
$password = new SoapVar($password, XSD_STRING, null, null, 'Password', $wssNamespace);
$usernameToken = new SoapVar(array($username, $password), SOAP_ENC_OBJECT, null, null,'UsernameToken', $wssNamespace);
$usernameToken = new SoapVar(array($usernameToken), SOAP_ENC_OBJECT, null, null, null, $wssNamespace);
$wssUsernameTokenHeader = new SoapHeader($wssNamespace, 'Security', $usernameToken);
$Client->__setSoapHeaders($wssUsernameTokenHeader);
}
就像我之前说的,如果我直接从浏览器运行这个页面,它工作得很好,但是当我试图让Windows任务调度程序运行这个页面时,它只会给我这个错误。
感谢Andrej,如果您有两个php.ini文件,则需要确保两个php.ini文件都打开了soap模块。我有两个,一个在Apache文件夹,一个在PHP文件夹