Create a PHP service script that is responsible for crawling communication records such as MQTT and saving them to the database. Usually, we just open a terminal on the server side, you can run the code, to catch the data, but the terminal is closed, you will not be able to crawl the data. The daemon (daemon) is the process that is running in the background (daemon). He can run away from the terminal alone in the background.
foreground tasks and background tasks
1. On Ubuntu, the usual practice is to run the following code as a service script.
PHP run.php
This makes it possible to run a terminal on its own. But you can't use the terminal to do anything else.
2. We add & at the end of the order, as follows:
PHP run.php &
As long as the symbol & is added at the end of the command, the started process becomes a "background task." If you want a running foreground task to become a background task, you can press CTRL + Z first, and then execute the BG command (let the most recent paused background task continue). You can also enter fg
a carriage return into normal mode.
"Background Tasks" has two features:
Inherits the standard output (STDOUT) and standard error (STDERR) of the current session (Dialog). Therefore, all the output from the background task is still displayed synchronously at the command line.
No longer inherits the standard input (stdin) of the current session. You cannot enter a command into this task. If it tries to read the standard input, it pauses execution (halt).
As you can see, the essential difference between "background tasks" and "foreground tasks" is only one: whether to inherit standard input. Therefore, the user can also enter additional commands while performing background tasks.
TAIL-FN Nohup.out