5

I'm currently experimenting with a PHP plugin called Mosquitto PHP (https://github.com/mgdm/Mosquitto-PHP/). I've got it all installed right, and under 'php -m' it seems to show up properly.

I'm using a small test code to see if it in it's basic form works:

<?php

$c = new Mosquitto\Client;
$c->onConnect(function() use ($c) {
    $c->publish('mgdm/test', 'Hello', 2);
});

$c->connect('test.mosquitto.org');

for ($i = 0; $i < 100; $i++) {
    // Loop around to permit the library to do its work
    $c->loop(1);
}

echo "Finished\n";
?>

And that seemed to return "Finished" in my browser. So, I decided to up my game, and add a TLS connection, as documented, to this:

<?php

$c = new Mosquitto\Client;
$c->onConnect(function() use ($c) {
    $c->publish('mgdm/test', 'Hello', 2);
});

$c->setTlsCertificates('mosquitto.org.crt');
$c->connect('test.mosquitto.org', '8883');

for ($i = 0; $i < 100; $i++) {
    $c->loop(1);
}

echo "Finished\n";
?>

I got the certificate and I've made sure apache2 could read it and set the ownership subsequently to apache2. This turned out to give me the 500 internal sever error in my browser.

-rwsrwsrwt  1 www-data     www-data        279 Jun  5 04:12 test.php
-rwxrwxrwx  1 www-data www-data   1078 Jun 30  2012 mosquitto.org.crt

Out of curiousity, I navigated to the script in shell and ran it with:

sudo php test.php

This resulting in a printed "Finished" in my ssh, and it sent the message through the broker.

This made me think it's an odd sort of permission error. Investigating further, I found these in my logs:

My apache2 log:

mod_fcgid: process /var/www/php-fcgi-scripts/web1/.php-fcgi-starter(20614) exit(communication error), get unexpected signal 11

mog_fcgid installed is:

libapache2-mod-fcgid 1:2.3.9-1+b1 amd64 FastCGI interface module for Apache 2

and it is, same with suexec is enabled as far as I can tell.:

Module fcgid already enabled
Module suexec already enabled

In a small twist of events, I changed the .php to .fcgi and gave it +x permission, and now the messages goes through the broker, but still it gives a 500 error in my browser.

suexec log shows:

[2016-06-07 14:05:58]: uid: (5004/web1) gid: (5005/client0) cmd: test.fcgi

and in my ispconfig log it shows:

[Tue Jun 07 14:08:25.567945 2016] [fcgid:warn] [pid 27861] (104)Connection reset by peer: [client 93.135.88.60:49328] mod_fcgid: error reading data from FastCGI server
[Tue Jun 07 14:08:25.568016 2016] [core:error] [pid 27861] [client 93.135.88.60:49328] End of script output before headers: test.fcgi

I'm totally lost for words here.. I need help!!

Machavity
  • 30,841
  • 27
  • 92
  • 100
user5740843
  • 1,540
  • 5
  • 22
  • 42

1 Answers1

3

Try to increase the memory for php-fcgi (by default for cli memory_limit=-1).

I think this case should resolve your problem.

UPDATE

I have installed mosquitto (from php7 branch) and try it (run test.php from repository examples. php 7.0.7). And i have segfault to

segfault at 8 ip 00005574a41c753f sp 00007ffc2dc85da0 error 6 in php7.0[5574a3f80000+391000]

It seems that this is extension bug. You can try to debug this segfault (https://bugs.php.net/bugs-generating-backtrace.php) and send report to extension developers.

Dmytro
  • 572
  • 9
  • 29
  • 1
    Try to set 512M. Or change limit for cli configuration (set 128 instead of -1), to verify that is memory problem – Dmytro Jun 07 '16 at 06:25
  • 1
    I don't know about php-fcgi, but php-fpm and php-cli have different config file (i think php-fcgi too have different config - maybe /etc/php/fcgi/php.ini, or something like this). – Dmytro Jun 07 '16 at 06:33
  • /etc/php5/cgi/php.ini & /etc/php5/cli/php.ini & /etc/php5/fpm/php.ini all have "memory_limit = 512M", restarted apache2, same result. 500 in brower and same errors in all logs. – user5740843 Jun 07 '16 at 06:39
  • The segfault for the php7 branch is expected to fail. This is still in progress as he mentioned in his README. I'm using php5.6 branch where it is supposed to work. – user5740843 Jun 07 '16 at 11:29
  • 1
    But anyway, signal 11 - this is segfault. you can debug it ((https://bugs.php.net/bugs-generating-backtrace.php) – Dmytro Jun 07 '16 at 12:23