Ubuntu running the background PHP service detailed

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.