Javascript-php is implemented in the background. After the execution is completed, the front-end is notified.

Source: Internet
Author: User
Currently, php is used to execute the script. However, if the script is disabled on the front-end page, the script execution is terminated. to switch to the background, you can run the script on the front-end, but the running Progress is provided, for example, the current real-time update execution status, for example, has been executed to 80%, and after 100% is completed, the prompt is complete... currently, php is used to execute the script. However, if the script is disabled on the front-end page, the script will be terminated, so you want to switch to the background to run the script.

Another method is to run on the foreground, but provide the running progress. For example, the current real-time update execution status, for example, has been executed to 80%, and then prompts the completion information after 100% is completed.

For example, video transcoding is currently being transcoded and you want to transcode it in the background without affecting the operations on the foreground.
Another operation occupies the front-end, but it can tell the front-end that transcoding is still in progress and how many transcoding tasks are not performed.

Reply content:

Currently, php is used to execute the script. However, if the script is disabled on the front-end page, the script will be terminated, so you want to switch to the background to run the script.

Another method is to run on the foreground, but provide the running progress. For example, the current real-time update execution status, for example, has been executed to 80%, and then prompts the completion information after 100% is completed.

For example, video transcoding is currently being transcoded and you want to transcode it in the background without affecting the operations on the foreground.
Another operation occupies the front-end, but it can tell the front-end that transcoding is still in progress and how many transcoding tasks are not performed.

Video Transcoding, time-consuming, should not block the PHP-FPM process, so it should be another process asynchronous processing:
pclose(popen('php /path/to/task.php &', 'r'));
Run the Linux Command in task. php.mencoder/ffmpeg/imagemagick(convert)Process multimedia files,
Insert a data entry into the database task table to record the task status and progress for front-end AJAX check.

1. the transcoding service is a process that provides two interfaces (a: accept and process transcoding requests, B: Query transcoding progress)
2. The frontend can call these two interfaces.

For these two types. What I learned in the background is to create a data table, such as video transcoding and email sending. To perform the corresponding operation, insert data to the database, then write a scheduled task to complete related operations in the background.

Execute and display the progress bar on the front-end. Take each operation as one step and calculate the total number of steps. More steps are involved.

Swoole extensions can be used for background Asynchronization.
As for the progress, you can use a database or redis for communication. For example, if the progress is over 5%, update the database or redis. The frontend queries the latest status every 10 seconds.

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.