32

How can I check whether the server is able to handle SOAP requests at run time ? I need to verify it before my script is executing.

Epoc
  • 7,208
  • 8
  • 62
  • 66
phpqa.in
  • 589
  • 3
  • 8
  • 16
  • I think you can not tell if a server has SOAP enabled. What if you can do is find out is if the server has a specific SOAP service running. – Lobo May 25 '12 at 07:12

8 Answers8

36

You can use:

if (extension_loaded('soap')) {
  // Do things
}

http://php.net/manual/en/function.extension-loaded.php

Epoc
  • 7,208
  • 8
  • 62
  • 66
19

From SSH you can run:

php -i | grep Soap

that will return something like:

Soap Client => enabled
Soap Server => enabled
Marty Staas
  • 401
  • 4
  • 8
SilverNodashi
  • 352
  • 3
  • 11
15

In PHP to check whether SOAP enabled or not use built in function class_exists():

var_dump(class_exists("SOAPClient"));

It also could be user to check any of modules classes.

s.webbandit
  • 16,332
  • 16
  • 58
  • 82
  • 1
    Why was this answer down-voted? It's a lot more direct and usable than the `phpinfo` "solutions", and perhaps even more direct than `extension_loaded`. – meustrus Jul 10 '14 at 21:00
  • 1
    Because the OP wants to check SOAP at run time before its script is executing. See the question. – Epoc Sep 12 '14 at 19:47
6

in the command line type the following:

>>  php -r 'echo (extension_loaded("soap")?"LOADED\n":"not loaded\n");'
Ivan
  • 34,531
  • 8
  • 55
  • 100
Grigoreas P.
  • 2,452
  • 25
  • 19
4

in a php file :

<?php
echo phpinfo();
?>

and then look for SOAP and you will see if SOAP is installed and enabled

EDIT : be careful with other solutions using php CLI (Command Line Interface), because you don't have the same php.ini used for the CLI and for your web server (for example apache). Thus it may differ.

Then if you use apache and you want to see if soap is enabled, it's better to indicate the apache php.ini file in the command line, for instance :

php -c /etc/php/apache2/php.ini -i | grep Soap
Nico
  • 3,430
  • 4
  • 20
  • 27
4

Hmm... I'm new and I'm bad : I tried this in a "test.php" file.

<?php
    if (extension_loaded('soap')) 
    {
        echo phpinfo();
    }
    else //will redirect to sth else so you know it doesn't work
    {
        header("Location: http://localhost/index.html");
        die();
    }
?>

And I saw myself looking at a "phpinfo()" page with a paragraph called : "soap".

Sorry for the misinterpretation.

To install SOAP :
Check your "php.ini" file, look for "extension".
You should find a line :
extension=php_soap.dll or ;extension=php_soap.dll
";" means it's commented.
Uncomment it.
If you didn't find the line, then put it there.
extension=php_soap.dll
Make sure the dll file actually is in the default folder php/ext. If it isn't, check on phpinfo() is your version is VC6, VC9 of VC11, go to the php download page : http://windows.php.net/download#php-5.6 and get the correspondant version of php zip file.
Steal their "php_soap.dll" from their /ext folder and put it in yours.
You're all set!
Restart your servers, then go to your phpinfo() test page to check if it works.

Good luck.
Note : phpinfo() simple test.php file :

<php
    echo phpinfo();
?>
1

PEAR packages are not listed in phpinfo(), so if "soap" doesn't appear on your "test.php" page, it's normal !

0

You can use the phpinfo script to see is SOAP is installed.

http://[your-domain.com]/phpinfo.php

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Ray
  • 17
  • 1