skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    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);
    }
    

  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search