PHP from command line records nothing

I have a Slim 3.8 project that works with Sentry 2.0. But when I run scripts from the command line, nothing ends up in Sentry.

I’ve printed promise and response objects all the way into the HttpTransport class and see that messages are being built and sent. But nothing appears in Sentry. And I cannot tell what the status of the send is. Last thing I see is the promise is status “pending”.

Is there some magic to get PHP scripts from the command line to work with Sentry? Is there an easy way to debug lower-level stuff like this, like some way to turn on extra debug info within sentry?

Hey :slight_smile:

Are you using the latest version of the SDK 2.2.x?
The Issue should be fixed there.

I’m using SDK 2.2.2. Did it get fixed in 2.2.3? If there’s any online references to this (bugfix, pull-request, other forum posts, etc), I’d love to see them in case they have hints on what is happening.

I believe it is this PR that fixed it: Fix regression on default sending behavior of the HttpTransport transport by ste93cry · Pull Request #905 · getsentry/sentry-php · GitHub

Here are the release notes for 2.2.3: Release 2.2.3 · getsentry/sentry-php · GitHub

I upgraded to 2.2.3 and whatever I’m seeing isn’t fixed. I’ve narrowed my code down to the most basic case. Am I missing something?

$loader = require_once APP_ROOT . '/vendor/autoload.php';

\Sentry\init([
    'dsn' => 'https://XXXXXXX@sentry.io/YYYYY',
]);

\Sentry\captureMessage('test message');

Ping @HazAT @kamilogorek

Thanks for the repo, in fact I was trying out exactly the same and it worked from me.

<?php

include_once('./vendor/autoload.php');

$DSN = 'http://813a1bd5c89b4dadb2695b3a96d6421f@sentry.io/3235';
Sentry\init([
    'dsn' => $DSN,
]);
$res = Sentry\captureMessage('testCLI');
echo $res;
➜ php index.php
23e3b05cc1714e7789ac51d71d94ff2f%

How does your composer file look like? Are you using sentry/sdk?

"require": {
    "sentry/sdk": "^2"
  },

Are you running self hosted version of Sentry or sentry.io?

Figured it out! I had a config issue, but will describe what happened in case it helps others. I apologize for wasting anyone’s time answering this.

I’m on a Windows system, running WAMP. I have a batch script that I run from the command-line to put the PHP executable on the system path, so it can be quickly run by typing “php”.

WAMP has two php.ini files in each of it’s PHP version folders. One called php.ini, and one called phpForApache.ini. The change I made to the Apache version (to make Sentry work when in a webpage), was not applied to the normal php.ini files, which the command line uses.

The change needed was to give curl a valid cert file, in the curl.cainfo setting. I use the one bundled with Firefox.

What would be nice

I’m not sure why Sentry v2 on Windows requires a CA cert this when v1 didn’t. But I’ve seen this issue in a few threads. It would be great if Sentry could check for this and warn the user, or document it better. Or at the least throw a meaningful error when the curl promise fails too many times. This issue was definitely my fault, but some sort of notification would have gone a long way to helping diagnose it.

2 Likes

Thank you for your explanation!
Just to reverify, you call to Sentry\captureMessage returned null correct?

Nevertheless, I agree, maybe if you turn on “debug mode” (which is yet to be implemented) of the SDK we could throw the error so you see what’s happening.