1

I'm developing a pretty simple wordpress plugin to connect to a soap service. It works fine on my localhost, but on a production hosting (I tried two different ones) it returns this error:

SoapClient Object ( [trace] => 1 [_exceptions] => [_stream_context] => Resource id #303 [_soap_version] => 1 [sdl] => Resource id #304 ) Fatal error: Uncaught Error: Call to a member function GetModelfunctions() on bool in /home/.sites/278/site7279787/web/jobs/wp-content/plugins/hrjobs/jobsview.php:14...

This is the function:

function hrjobsinit() {
    $wsdl = WSDL_PATH;
        $handle = curl_init($wsdl);
        curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
        $response = curl_exec($handle);
        $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    if ($httpCode > 399)
    {
        $client = null;
    }
    else
    {   
                $client = new SoapClient($wsdl, array(
                    'exceptions' => 0,
            'trace' =>true  
                ));
    }
        curl_close($handle);
    return $client;
}

My localhost is PHP Version 7.2.24-0ubuntu0.19.04.2, Apache/2.4.38, cURL 7.64.0

The production hosting is Linux 3.10.0-962.3.2.lve1.5.27.el6h.x86_64, cURL 7.61.0, I've noticed that some cURL stuff is not enabled (IDN, TLS-SRP, PSL) in the production server where it's not working.

Caio Oliveira
  • 1,243
  • 13
  • 22
Broldev
  • 13
  • 2

2 Answers2

0

First of all set the initialization of the SoapClient class in a try/catch block. The SoapClient throws an Exception as a SoapFault instance, when an error occurs. as long as you 're in development mode, enable the exceptions. This will make things easier.

try {
    $client = new SoapClient($wsdl, $options);
} catch (SoapFault $fault) {
    var_dump($fault);
}

The error message you provided says, that you call a webservice method on null. So I guess the initialization of your client was not successfull. Have you checked, if the soap extension is available on your webspace? To check that, just output the phpinfo() on your webspace and search for soap/ext. If you have access to your server, follow the answer in this question: How do I install soap extension? otherwise ask your provider, if the soap extension can be enabled.

Marcel
  • 4,854
  • 1
  • 14
  • 24
  • Thanks Marcel, I've checked phpinfo for soap extension it's enabled both in my local machine and in the hosting machine - sorry I didn't mention. Curl is reading the wsdl file correctly in both machines. Locally also the SoapClient is getting all the data as it should. In the hosting environment something is going wrong and I just can't figure out what. – Broldev Apr 26 '20 at 14:14
  • Waht is the http code on your production environment? Why you 're using curl to get informations about the wsdl file instead of using the wsdl file directly with the SoapClient class? – Marcel Apr 26 '20 at 16:24
  • you're right you don't need curl. but the problem remains the same. it works locally but not in the production host. I'm actually rewriting an existing typo3 extension as a wordpress plugin. – Broldev Apr 26 '20 at 16:39
  • Did you follow the try/catch hint? Ist there an exception thrown, wenn initializing with the wsdl? – Marcel Apr 26 '20 at 17:24
  • It looks like my production server (all of them) are not allowing to contact the remote server. Now I tried to connect to the remote wsdl directly (previously the wsdl file was local). Both works from my machine, but not from the production server. It could be anything I guess, port probably? It's 85 – Broldev Apr 26 '20 at 17:38
  • 1
    omg so embarrassing the port 85 was not enabled. i.e. all ports were disabled. that was the problem. – Broldev Apr 28 '20 at 13:32
0

It was just that the port of the service (in this case 85) was not enabled in the shared hosting, where I was testing. Second thing curl is not needed one can call the SoapClient directly.

   try {
    $client = new SoapClient($wsdl, $options);
} catch (SoapFault $fault) {
    var_dump($fault);
}
Broldev
  • 13
  • 2