How to run MQTT internally on linux server to publish and subscribe data using PHP

3,105 views
Skip to first unread message

Naveenkumar Tarigonda

unread,
Jan 5, 2015, 9:27:17 AM1/5/15
to mq...@googlegroups.com
Hi,

I'm new to MQTT, we created sample project to store temperature value coming from sensor at every 5 min. interval and we able store data to MySQL database and this process is working till MQTT client subscription file,  "temp_subscribe.php" in open, if we close "temp_subscribe.php" data not storing to database. 

could any one please provide me help to run publish/subscribe even PHP file in close. We're running MQTT in Linux Apache server.

Thank you

Nicholas Humfrey

unread,
Jan 5, 2015, 1:37:55 PM1/5/15
to mq...@googlegroups.com
PHP is best suited to serving web pages, in very short lived processes. Setting up a long running process to handle messages received over MQTT is possible but you might be better using a different language. Apache httpd certainly wouldn't be needed.

Why not just write to the database directly from PHP?

Sent from my phone
--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
To post to this group, send email to mq...@googlegroups.com.
Visit this group at http://groups.google.com/group/mqtt.
For more options, visit https://groups.google.com/d/optout.

Naveenkumar Tarigonda

unread,
Jan 6, 2015, 7:38:16 AM1/6/15
to mq...@googlegroups.com
Thanks for your kind replay.
Could you pls give me an example small snippet of code to save MQTT data to MySQL using PHP without running cron jobs, really it will be help full for us.

Thank you

Naveenkumar Tarigonda

unread,
Jan 6, 2015, 7:43:33 AM1/6/15
to mq...@googlegroups.com
Right now we would plan to run cron job at linux server at every one minute and capture subscription topic data from MQTT and store in MySQL database using PHP in background process. But we do not know whether this is the right approach or not.
Pls suggest us. 


On Tuesday, January 6, 2015 12:07:55 AM UTC+5:30, Nicholas Humfrey wrote:

Stefano Costa

unread,
Jan 6, 2015, 7:55:12 AM1/6/15
to mq...@googlegroups.com
An MQTT broker by its nature delivers messages in real time to subscribing clients, asynchronously. Cron every minute (or any other interval and similar approach) will not work: you will get only messages published with persistent flag set.

Instead a common and reasonable approach is preparing a daemon running forever that subscribes to relevant topics (or "anything") and saves received messages to MySQL or whatever.

You will find plenty of examples, perhaps the simple way is writing a daemon using Paho Python library. Or you could have a look at the "mqttwarn" daemon written by JP Mens (https://github.com/jpmens/mqttwarn) there's a MySQL plug.

S

Naveenkumar Tarigonda

unread,
Jan 8, 2015, 12:54:48 AM1/8/15
to mq...@googlegroups.com
Thanks for your kind reply

Could you pls suggest me where can we found/ how to Installation steps of Mosquitto MQTT Broker in Amazon Web services EC2 (AWS EC2) Linux environment with websockets enabled.

Siddharth Dutt Choubey

unread,
Oct 23, 2017, 3:56:27 AM10/23/17
to MQTT
Hello naveen kumar, i am new in MQTT, i have installed MQTT - Mosquito in my local machine (ubuntu 16.04 LTS), but i am not able to connect it PHP & mysql  (I want to access MQTT using PHP) . please give me some guide line .

Thanks
Reply all
Reply to author
Forward
0 new messages