Fatal error: Cannot instantiate non-existent class: soapclient in - php

its works by hit url but in cronjob script not workes.Cannot instantiate non-existent class: soapclient in command prompt.
$wsdl ='********/InvoicingService?wsdl';
$client = new SoapClient($wsdl, array("trace"=> 1,"exceptions" => 0));
$invoicecheck = array("username" => "*****","password" => "*****","invoiceNo" =>"****");
$proxy = $client->getProxy();
$value2 = $client ->checkInvStatus($invoicecheck);
$statusInvoice=$value2->return->responseMessage;
if($statusInvoice=='Paid'){
mail('mahtab46#gmail.com','wsdl check cron mail','paid');
echo 'working';
} else {
echo 'not worked';
}

The cronjob executes the PHP CLI handler. This probably uses a different php.ini that doesn't load the soap extension. Try to have php run a php -i > /tmp/test.txt or something and see if the Soap functionality is in there?

Related

soap class run correctly on localhost but don't run on server

i have a problem with soap class in php. i have write a code to send sms via a sms panel. these codes run correctly on localhost (when run codes by xampp on my pc) but this code don't work when i run them on server. the php versions are same on both of them (localhost and xampp)
<?php
$FORM="30005966371";
$USERNAME="xxxx";
$PASSWORD="12345";
$DOMAIN="0098";
//---- variables ----
$TO="0935xxxxxxx";
$TEXT="test msg";
//-------------------
ini_set("soap.wsdl_cache_enabled", "0");
$sms_client = new SoapClient('http://webservice.0098sms.com/service.asmx?wsdl',array('encoding'=>'UTF-8'));
$parameters['username'] = $USERNAME;
$parameters['password'] = $PASSWORD;
$parameters['mobileno'] = $TO;
$parameters['pnlno'] = $FORM;
$parameters['text']=$TEXT;
$parameters['isflash'] =false;
echo $sms_client->SendSMS($parameters)->SendSMSResult;
?>
when i run above codes on localhost the message sends correctly but when run this code on server the following error returns:
bimehco.ir is currently unable to handle this request.
HTTP ERROR 500
i enabled soap extension in php.ini file on server but it still dont work correctly.
The initialization of the SoapClient class should look as follows when searching for errors.
$wsdl = 'http://webservice.0098sms.com/service.asmx?wsdl';
$options = [
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => true,
'trace' => true,
];
try {
$client = new SoapClient($wsdl, $options);
// do your request stuff here
} catch (SoapFault $fault) {
echo $fault->getMessage();
if ($client instanceof SoapClient) {
echo $client->__getLastRequest();
echo $client->__getLastResponse();
}
}
my soap codes were true and don't have any problem. it was a problem on host.
you can use above codes for soap.
or you can use curve function instead.

SoapFault exception: [VersionMismatch] Wrong Version

I made one of SOAP web service on local machine. I call with a SOAP client via the some.wsdl file, work fine. But I try to use full host-URL http://flow.local/soap/some.wsdl
The index.php (with SOAP) client:
<?php
//Here change the client to 'some wsdl' / 'http://flow.local/soap/some.wsdl'
$client = new SoapClient("http://flow.local/soap/some.wsdl",
array('soap_version' => SOAP_1_2,'trace' => 1 ));
var_dump($client->__getFunctions());
$return = $client->__soapCall("hello",array("World"));
echo("\nReturning value: ".$return);
Here is the soap.php
<?php
function hello($someone)
{
return "Hello " . $someone . "! - With WSDL";
}
ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer("http://flow.local/soap/some.wsdl",
array('soap_version' => SOAP_1_2));
$server->addFunction("hello");
$server->handle();
And of course I have a wsdl schema file.
When I use full URL http://flow.local/soap/some.wsdl returns with:
"Fatal error: Uncaught SoapFault exception: [VersionMismatch] Wrong Version!"
Else work fine.
Win10Pro, WAMP server, PHP version 7.2.18.

PHP SOAP Web Service

I am trying to create a simple PHP webservice as I am a newbie in this track. I decided to develop it using SOAP. I am using WAMP as a server and the problem is that I am unable to run the scripts nor get the WSDL file.
Here's server.php's code:
<?php
//call library
require_once ('lib/nusoap.php');
//using soap_server to create server object
$server = new soap_server;
//register a function that works on server
$server->register('get_message');
// create the function
function get_message($your_name)
{
if(!$your_name){
return new soap_fault('Client','','Put Your Name!');
}
$result = "Hello World ".$your_name .". Thanks for Your First Web Service Using PHP with SOAP";
return $result;
}
// create HTTP listener
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
and here's a screenshot of the run:
Here's client.php's code:
<?php
require_once ('lib/nusoap.php');
//Give it value at parameter
$param = array( 'your_name' => 'Omar');
//Create object that referer a web services
$client = new soapclient('http://localhost/WebServiceSOAP/server.php');
//Call a function at server and send parameters too
$response = $client->call('get_message',$param);
//Process result
if($client->fault)
{
echo "FAULT: <p>Code: (".$client->faultcode."</p>";
echo "String: ".$client->faultstring;
}
else
{
echo $response;
}
?>
and here's a screenshot of the run:
running client.php
plus this error keeps bugging me:
Undefined variable: HTTP_RAW_POST_DATA
can u try this below code
$client = new soapclient('http://localhost/WebServiceSOAP/server.php');
to
$client = new SoapClient(
null,
array(
'location' => 'ADD YOUR LOCATION',
'uri' => 'ADD YOUR WSDL FILE ',
'trace' => 1,
'use' => SOAP_LITERAL,
)
);
You're trying to work with undefined variable $HTTP_RAW_POST_DATA. In PHP7 this hook is removed. You can read here
Instead of that I propose to do it like this:
$server->service(file_get_contents("php://input"));

PHP gearman connection error

I trying to run a task in PHP using gearman I created 2 scripts:
client.php
<?
$mail = array(
'to' => 'test#gmail.com',
'subject' => Hi',
'body' => 'Test message',
);
# Connect to Gearman server
$client = new GearmanClient();
$client->addServer('127.0.0.1', '4730');
# Send message
$client->doBackground('sendmail', json_encode($mail));
worker.php
<?php
$worker = new GearmanWorker();
$worker->addServer();
$worker->addFunction('sendmail', 'send_mail');
while (1)
{
$worker->work();
if ($worker->returnCode() != GEARMAN_SUCCESS) break;
}
function send_mail($job)
{
$workload = $job->workload();
$data = json_decode($workload, true);
mail($data['to'], $data['subject'], $data['body']);
}
when I run my worker from comand line : php worker.php &
and run my client.php file I get the below error:
GearmanClient::doBackground(): send_packet(GEARMAN_COULD_NOT_CONNECT) Failed to send server-options packet -> libgearman/connection.cc:485
Any help please?
Thanks
Try to change this:
$client->addServer('127.0.0.1', '4730');
to
$client->addServer();
If still no working, try to take a look in the get started page of this tutorial on php. It worked fine for me
You forgot to start gearman by running gearmand -d
Read more about it in the documentation at http://gearman.org/getting-started/

Consume wadl service in php

I need to call a method from a wadl service and pass a parameter
wadl: http://domain.com/application.wadl
method: checkInfo
How can i do that?
//Wsdl - Soap: I need to do this but with a wadl service
$wsdl = new SoapClient('http://domain.com/application?wsdl');
$wsdl->__call('checkInfo',array('data'=> ''));
//or
$wsdl->checkInfo(array('data'=> ''));
Thank you!!!!
you can do this by using SOAP server :
class MyClass{
function checkInfo() {
return "Hello";
}
}
//when in non-wsdl mode the uri option must be specified
$options=array('uri'=>'http://localhost/');
//create a new SOAP server
$server = new SoapServer(NULL,$options);
//attach the API class to the SOAP Server
$server->setClass('MyClass');
//start the SOAP requests handler
$server->handle();
then use it :
<?php
/*
* PHP SOAP - How to create a SOAP Server and a SOAP Client
*/
$options = array('location' => 'http://localhost/server.php',
'uri' => 'http://localhost/');
//create an instante of the SOAPClient (the API will be available)
$api = new SoapClient(NULL, $options);
//call an API method
echo $api->checkInfo();
?>
code example from here

Categories