NativePHP / laravel

Laravel wrapper for the NativePHP framework
https://nativephp.com
MIT License
3.18k stars 164 forks source link

Scheduled Commands #313

Open connor-devuk opened 5 months ago

connor-devuk commented 5 months ago

What were you trying to do?

I have a command which sends some data to my API every 30 minutes.

What happened?

I cannot have scheduled commands to call my API because it errors with a curl ssl error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://xxxxxx.xxxx

Now I know you'd think this is a me issue however I think its todo with the way you run the schedule command, as if I run the php artisan schedule:run command manually or the actual artisan command I have for it, it works just fine.

Maybe it's something i have setup weirdly on my end but to my knowledge everything is fine

How to reproduce the bug

Have a scheduled command run every minute (or whatever) and have it call send an API request via Laravels Http library

Package Versions

0.5.1

PHP Version

8.1

Laravel Version

10.48

Node Version

18.18.2

Which operating systems have you seen this occur on?

macOS

OS version

macos14.4.1

Notes

No response

simonhamp commented 3 months ago

@connor-devuk are you trying to call a public service or a local test service with a self-signed cert? (e.g. a secure Herd or Valet site)

simonhamp commented 3 months ago

I've managed to reproduce this only when I'm calling a service that's using a self-signed certificate.

If you're using Laravel's HTTP facade (which is built on top of Guzzle), you can get around this by adding the following to your AppServiceProvider:

use Illuminate\Support\Facades\Http;

public function boot(): void
{
    if ($this->app->environment('local')) {
        Http::globalOptions([
            'verify' => false
        ]);
}

Of course, in practice, you don't want to bypass certificate verification like this for anything important, as you can't trust that the certificate is valid and thus that the TLS connection is safe.

connor-devuk commented 3 months ago

I've managed to reproduce this only when I'm calling a service that's using a self-signed certificate.

If you're using Laravel's HTTP facade (which is built on top of Guzzle), you can get around this by adding the following to your AppServiceProvider:


use Illuminate\Support\Facades\Http;

public function boot(): void

{

    if ($this->app->environment('local')) {

        Http::globalOptions([

            'verify' => false

        ]);

}

Of course, in practice, you don't want to bypass certificate verification like this for anything important, as you can't trust that the certificate is valid and thus that the TLS connection is safe.

@simonhamp I come across this issue when calling my services API end point hosted on AWS which has an SSL certificate issued by LetsEncrypt