How do I display files generated by the background program in real time?

Source: Internet
Author: User
I am writing a php program. the function is to call a backend computing program after receiving the parameters passed by the front-end to generate an image based on this parameter (this process takes some time, about 2 S ). Finally, on the interface, I need to wait for the image to be generated and then display the image in a d... problem

I am writing a php program. the function is to call a background computing program after receiving the parameters passed by the front-end to generate an image based on this parameter (this process takes some time, about 2 S ).
Finally, on the interface, I need to display the image in a p after the image is generated.
So the problem is: during the image generation, the interface is in a unresponsive state;
In addition, if the program fails and the image is not generated, I cannot know it;

Solution

The solution I use now is to use setInterval to check whether the image is generated every second. If yes, the image url will be sent to the target img tag of the front-end. If the url is not obtained in 10 seconds, the generation fails.

However, this method is stupid, and it takes a long time to know if it fails.

So I would like to ask if you have any good suggestions or implementation methods to improve the user experience in this process?

Reply content: question

I am writing a php program. the function is to call a background computing program after receiving the parameters passed by the front-end to generate an image based on this parameter (this process takes some time, about 2 S ).
Finally, on the interface, I need to display the image in a p after the image is generated.
So the problem is: during the image generation, the interface is in a unresponsive state;
In addition, if the program fails and the image is not generated, I cannot know it;

Solution

The solution I use now is to use setInterval to check whether the image is generated every second. If yes, the image url will be sent to the target img tag of the front-end. If the url is not obtained in 10 seconds, the generation fails.

However, this method is stupid, and it takes a long time to know if it fails.

So I would like to ask if you have any good suggestions or implementation methods to improve the user experience in this process?

  • You can build a loading interface, simply find a GIF in a circle to fill that p,

  • You can use websocket to check whether images are generated,

  • Another suggestion is to determine whether an image can be generated successfully in the image generation program. if not, generate an image that represents an error, so that the image can be uploaded to the front-end.

The key here is that it is best not to use the logic of "10 seconds without feedback, certainly failed. Instead, the system fails in the background, and immediately calls the code block for error handling, returns a message, and notifies the user of the failure. I don't quite understand how php is handled. in python:

Try: # try to execute the following code. if the code fails, execute the code in memory t # write the image creation logic here, image =... return success (message = 'done. ', data = image) # returns the success message and the image watermark T Exception as ex: # in case of an Error logger (ex) # records the Error document return fail (message = 'Error. ') # return the failed message immediately, instead of waiting for 10 seconds.

Ajax can be solved, and success and failure callbacks can be processed. The new version also has timeout processing.

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.