PHP questions about cashing in on multithreading

Source: Internet
Author: User
PHP's Questions about implementing multithreading
I want to implement a function. is to read more than one data from the database first.

The specified function is then executed according to an item in the data.

Because the algorithm cumbersome, time-consuming long, I would like to give the backstage to deal with. But I don't know what a good way to achieve it.

For example

$a = new Data ("a");
$b = new Data ("B");
I want to jump directly to the request to execute $b after sending a $ A request, and so on.
Instead of waiting for a $ A request to complete, go to the next $b.

What's the best way? The data function is with multiple parameters:

------Solution--------------------
You can create a new PHP program file such as runonbackground.php
Then, the program that is displayed is also responsible for the asynchronous request runonbackground.php
You can use the fsockopen () or socket series functions to send asynchronous requests so you don't have to wait for the return value. And in the runonbackground.php page to do complex calculations, of course, you can also submit some parameters

As for multi-process, running in CGI mode under Linux and opening the pcntl extension can be used, but far more complex than the above method
------Solution--------------------
The manual has the Fsockopen example usage, you just need to initiate the requested code:
$fp = Fsockopen ("www.example.com", $errno, $errstr, 30);
if (! $fp) {
echo "$errstr ($errno)
\ n ";
} else {
$out = "Get/runonbackground.php?id=1&mode=hello http/1.1\r\n";
$out. = "host:www.example.com\r\n";
$out. = "connection:close\r\n\r\n";
Fwrite ($fp, $out);
}
Anyway, disconnect.
Fclose ($FP);

Get the parameters in runonbackground.php by $_get[' id '] $_get[' mode '), you know
  • 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.