PHP ajax asynchronous execution without waiting for execution results

Source: Internet
Author: User

PHP ajax asynchronous execution without waiting for execution results

This article mainly introduces how to handle PHP ajax asynchronous execution without waiting for execution results. This article provides the implementation code directly. For more information, see

When generating an application with a short address, you must generate a web snapshot based on the long address. This generated time is not instantaneous and cannot be estimated.

Therefore, the front-end solution generally displays the generated short address first, and then regularly checks whether the Web snapshot is generated.

So, PHP code is processed as follows:

The Code is as follows:

// The server uses phantomjs to generate Web snapshots.

$ Cd = '/home/emp/phpinstall/phantomjs-1.5.0/bin/phantomjs/home/emp/phpinstall/phantomjs/snap. js "'. $ url. '"/home/emp/public_html_demo/cms /'. $ thumb. '&';

Try {

@ Pclose (popen ($ cd, "r "));

} Catch (Exception $ e ){}

Front-end Js ajax script:

The Code is as follows:

_ Wt = window. setInterval ("sys. ajax ('? M = signed URL & c = index & a = check_snap ', '', callback. checkSnap);", 200 );

The callback function checkSnap waits for PHP's check_snap to check whether the webpage snapshot file has been generated.

After receiving the generated information, the _ wt timer is clear.

The Code is as follows:

ClearTimeout (_ wt );

In this way, PHP and the front-end AJAX work happily with JFYF ~

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.