0

I have a script, that works in background and accepts connections via unix sockets.

So, I've wrote another script, that connects to the first one.
I've checked it from the CLI and everything works just fine.
But when I'm trying to use my second script from the web (php-fpm), I'm getting exception No such file or directory.
This exception is thrown when socket_connect function is invoked.
Sounds like there is no socket file. But it does exist. And I can connect to this socket at that moment with this script but only from CLI.

Any ideas?

UPDATE:
Here is the code:

$filepath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'checkerd.sock';

$socket = socket_create(AF_UNIX, SOCK_STREAM, null);
$result = socket_connect($socket, $filepath, 0);
if ($result === false) {
    print_r(socket_strerror(socket_last_error()));
}
4
  • Please show some relevant code. Commented Mar 23, 2016 at 15:13
  • @CodeCaster, what concrete code do you want to see? Commented Mar 23, 2016 at 15:14
  • The code you use to create the listening socket and the code you use to connect to said socket. Also, the relevant configuration settings. Perhaps the user running the client php-fpm has no permissions to connect to the listening Unix socket, but that's just a guess. Commented Mar 23, 2016 at 15:15
  • @CodeCaster, I've updated the question with the code. Commented Mar 23, 2016 at 16:53

1 Answer 1

2

So, I've found an answer:

systemd has a feature "private tmp". It mounts /tmp (and /var/tmp) as private filesystem for each process.

My socket server was run from console (on behalf of php cli). Thats why I was able to connect to it when I run my client as console script. And that's why the same script hadn't seen socket file when was run from php-fpm (another process).

The solution is to disable private tmp for php-fpm:
I've created /etc/systemd/system/php-fpm.service.d/private-tmp.conf with the content:

[Service]
PrivateTmp=false

php-fpm must be restarted after this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.