Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

THRIFT-1482: Unix domain socket support under PHP #3109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

balping
Copy link

@balping balping commented Mar 9, 2025

To open a unix socket, the port number supplied to fsockopen (and pfsockopen) has to be -1.

We use substr instead of str_starts_with to keep compatibility with php 7.

Now a UDS can be created like this:

new TSocket('unix:///tmp/ipc.sock', -1)
  • Did you create an Apache Jira ticket? (Request account here, not required for trivial changes)
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
  • Did you squash your changes to a single commit? (not required, but preferred)
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
  • If your change does not involve any code, include [skip ci] anywhere in the commit message to free up build resources.

Client: php

To open a unix socket, the port number supplied to fsockopen (and pfsockopen) has to be -1.

We use substr instead of str_starts_with to keep compatibility with php 7.
@@ -218,7 +218,7 @@ public function open()
throw new TTransportException('Cannot open null host', TTransportException::NOT_OPEN);
}

if ($this->port_ <= 0) {
if ($this->port_ <= 0 && substr($this->host_, 0, strlen('unix://')) !== 'unix://') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can make this check like this

if ($this->port_ <= 0 && strpos($this->host_, 'unix://') !== 0) {

update a unit test lib/php/test/Unit/Lib/Transport/TSocketTest.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants