0

I have an artisan command where I do a soap call.

So I use the SoapClient

use SoapClient;

When I test run my command from an url like this:

Route::get('test-command', function() {
    Artisan::call('updateRegisterLogs');
});

Everything works great!

Now when I try to run it with artisan on my linux server to test the command to create a cronjob I get the following error:

[Symfony\Component\Debug\Exception\FatalThrowableError]

Class 'SoapClient' not found

The weird thing is I even get this error when I try a simple php artisan to see a list of all my commands.

Why does my artisan break from this? My code works fine but artisan doesn't.

Community
  • 1
  • 1
Michael
  • 556
  • 1
  • 8
  • 27
  • post the code of "updateRegisterLogs" command – FULL STACK DEV Apr 10 '19 at 08:35
  • @AdnanMumtaz it's a lot of code, the code works fine. I've tested it with calling the command via an url as shown in my question. The problem is my artisan breaks because of the `Class SoapClient not found` error – Michael Apr 10 '19 at 08:37
  • Possible duplicate of [PHP can not perform soap call from laravel command](https://stackoverflow.com/questions/55572708/php-can-not-perform-soap-call-from-laravel-command) – namelivia Apr 10 '19 at 08:43
  • @namelivia that question is not yet answered correctly since it has nothing to do with php.ini files. I reverted the changes in php.ini files and and my code still works fine but still same error – Michael Apr 10 '19 at 08:45
  • did you try? `use \SoapClient`, add a \ before SoapClient, because it's working for me – Sethu Apr 10 '19 at 09:00
  • yes I've tried that, same error unfortunately – Michael Apr 10 '19 at 09:08
  • did you check that, is Soap client installed on your server? you can check that using `phpinfo();` – Sethu Apr 10 '19 at 09:13
  • @Sethu I can execute soap calls from my code when I run the command with a route as explained in my question so yes soap client is installed – Michael Apr 10 '19 at 09:16
  • https://stackoverflow.com/questions/11391442/fatal-error-class-soapclient-not-found –  Apr 10 '19 at 09:37
  • @DevinGray As you can read in my question I am using a linux server not windows machine so I don't need no dll's – Michael Apr 10 '19 at 09:41
  • The php CLI Version on your Server differs from the php version of your webserver (apache, nginx). On the command line you use e.g. php5.6 where ext-soap is NOT installed, and apache uses php7.2 where ext-soap IS installed check both php Versions: php -v phpinfo(); artisan takes the cli version – IFR Apr 10 '19 at 11:54
  • @IFR is there perhaps a way to not use the cli version? make a command that redirects to a route or something – Michael Apr 10 '19 at 12:01
  • I would create a new class which handles your command code, then calls this class function from your command, or in your route function. Or make an alias inside your bash profile to use the correct php version or don't use Artisan::call rather use exec('php7.2 artisan '); – IFR Apr 11 '19 at 14:04

1 Answers1

1

The PHP version and also the CLI ini file could be different from the web one and when running command with artisan you are using the php cli. Check with php -r "echo phpinfo();" If your php cli has soap enabled.

Magicale
  • 11
  • 1