fix: infer ssl option from host protocol in PostHog::init#111
Open
fix: infer ssl option from host protocol in PostHog::init#111
Conversation
cleanHost() strips the protocol before QueueConsumer sees the host, so QueueConsumer never detects http:// and defaults ssl to true. This causes requests to http:// hosts (e.g. localhost) to fail silently with curl error 0 as the SDK tries to connect via HTTPS. Now PostHog::init() infers ssl from the host protocol before stripping it, unless the user has explicitly set the ssl option.
marandaneto
reviewed
Mar 28, 2026
Comment on lines
+45
to
+47
| if (substr($rawHost, 0, 7) === "http://") { | ||
| $options["ssl"] = false; | ||
| } elseif (substr($rawHost, 0, 8) === "https://") { |
Member
There was a problem hiding this comment.
can you do that with startsWith? its likely better than alocating a new string
its less error prone
if PHP < 8 we cna also do like if (strpos($rawHost, "http://") === 0)
do we support PHP 7 and older?
marandaneto
approved these changes
Mar 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ran into this small issue when testing against localhost (on http vs https)
Summary
PostHog::cleanHost()strips the protocol from the host beforeQueueConsumersees itQueueConsumerchecks forhttp://prefix to setssl=false, but the protocol is already gone, so it defaults tossl=truehttp://hosts (e.g.localhostfor local dev) to silently fail with curl error 0, as the SDK tries HTTPS against an HTTP serverPostHog::init()inferssslfrom the host protocol before stripping it, unless the user has explicitly set thessloptionChanges
lib/PostHog.php- detect protocol and setssloption beforecleanHost()strips ittest/PostHogTest.php- three new tests: http:// host, https:// host, and http:// via env varTest plan
testInitWithHttpHostSetsSslFalse,testInitWithHttpsHostSetsSslTrue,testInitWithEnvHttpHostSetsSslFalse)