Reputation: 1334
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()));
}
Upvotes: 0
Views: 889
Reputation: 1334
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.
Upvotes: 2