Skip to content

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

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

balping
Copy link
Contributor

@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.
@Jens-G Jens-G added the php label Mar 10, 2025
@sveneld
Copy link
Contributor

sveneld commented Apr 12, 2025

@balping apply this patch for test.

Index: lib/php/test/Unit/Lib/Transport/TSocketTest.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lib/php/test/Unit/Lib/Transport/TSocketTest.php b/lib/php/test/Unit/Lib/Transport/TSocketTest.php
--- a/lib/php/test/Unit/Lib/Transport/TSocketTest.php	(revision 19081602c35311ee13e6ba9ab2fa5001d182048b)
+++ b/lib/php/test/Unit/Lib/Transport/TSocketTest.php	(revision b1d4b05f352ded2ba5b78cb0a4f56dde01a11d41)
@@ -252,6 +252,7 @@
         $port = -1;
         $persist = false;
         $debugHandler = null;
+        $handle = fopen('php://memory', 'r+');
 
         $this->getFunctionMock('Thrift\Transport', 'fsockopen')
              ->expects($this->once())
@@ -261,7 +262,22 @@
                  $this->anything(), #$errno,
                  $this->anything(), #$errstr,
                  $this->anything() #$this->sendTimeoutSec_ + ($this->sendTimeoutUsec_ / 1000000),
-             );
+             )->willReturn($handle);
+
+        $this->getFunctionMock('Thrift\Transport', 'socket_import_stream')
+            ->expects($this->once())
+            ->with($handle)
+            ->willReturn(true);
+
+        $this->getFunctionMock('Thrift\Transport', 'socket_set_option')
+            ->expects($this->once())
+            ->with(
+                $this->anything(), #$socket,
+                SOL_TCP, #$level
+                TCP_NODELAY, #$option
+                1 #$value
+            )
+            ->willReturn(true);
 
         $transport = new TSocket(
             $host,

@Jens-G Jens-G closed this in 0481fcd Apr 18, 2025
@sveneld
Copy link
Contributor

sveneld commented Apr 18, 2025

@Jens-G what about failing tests?
patch for them should be applied...

@Jens-G
Copy link
Member

Jens-G commented Apr 18, 2025

@Jens-G what about failing tests? patch for them should be applied...

Just noticed and reverted.

@Jens-G Jens-G reopened this Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants