0

I am running Raspian on a Pi. I have a C++ app that is generating some real time data and I would like to make that data available to the web server (on the same Pi). I have a LAMP stack installed.

How would I go about doing such a thing?

I considered simply writing the data to a file and reading it with PHP on the web server. I am not sure that is a good idea since presumably it would be written to the SD card and cause wear. Should I set up a RAM disk, or is there a more direct way for the data to make its journey?

3 Answers 3

3

Since you are already running a LAMP server, I would write the data to your MySQL database, where it can be read via PHP and displayed.

The MySQL website has example code for writing to a MySQL database from C++.

This has one big advantage over a RAM disk or tmpfs it persists the data across restarts, allowing for long term storage and analysis.

1
  • 1
    Although I didn't comment about this in my answer, I think persistent storage of whatever form is better idea as well -- don't be scared of writing to the SD card, and don't believe a lot of the hysterics that can be found online about it. unix.stackexchange.com/a/84905/25985
    – goldilocks
    Commented Jan 5, 2017 at 4:59
3

Should I set up a RAM disk, or is there a more direct way for the data to make its journey?

In this context RAM disks have been superseded by tmpfs, which is simpler to use and probably already existent on whatever OS you are using, presuming it is a GNU/Linux variant. To check:

mount | grep "^tmpfs"

Chances are it includes /run, which is world readable, so you can create a writable directory in there with ownership and permissions appropriate to the process. Remember, obviously that doesn't persist across boots, and it will require superuser privileges to create the directory regardless of who is then allowed to use it. Hence, doing it via init is sensible; if the directory isn't used it doesn't matter.

/tmp is commonly also a tmpfs filesystem, but it is not on Raspbian.

You can find the maximum size and current usage stats via df. Beware the max size is probably a considerable potential chunk (e.g., on Raspbian it looks like /run has ~250 MB), meaning you have plenty of space but if you get out of control, that's RAM you're using. It sounds like you do not need much.

-3

Your best bet is using MySql , select either XML or JSON for your data format and you will reap the benefits of using these languages as well.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.