PHP Downloads A problem that is encountered when generating the required file type (relatively large).

Source: Internet
Author: User
At the beginning of each discovery, and later found more data, PHP script will be executed for a long time.

I simply took all the data and then judged it to match the search criteria, which is really cumbersome, but because the conditions are likely to be empty, I feel like I'm going to judge each condition as empty? Not empty, just add too much trouble to the SQL statement and not do that. (Can you tell me what the number is?)

Normal all conditions are empty, those if statements should not waste how long, so is to get the database that good 2, 30,000 data, and traverse this 2, 30,000 data generated the corresponding format of the string (with Html,txt and other formats) for a long time, more than max_execution_time = 30. (I set a very long, waited 2 minutes more, he did not lose out), more than that time, directly into the script, a white interface.

So my main problem is:

How to export that data, the leadership of the proposal is to read 1000, add a progress bar, and most of the online search is fixed files, there is a path can be directly under the, I this is generated, it is intended to use Ajax (not how to use, it is asynchronous request), and then see someone said Ajax can not download files , smarty templates, HTML and PHP files separate, looking for a long time do not know how to do, to help you the great God.


Reply to discussion (solution)

If it is me, the same as the idea of your leadership, paging to generate ...

Filter out empty entries for incoming conditions, available Array_diff
such as $_post = Array_diff ($_post, Array ("));
Without an empty item, it's much easier to assemble SQL.

Although normal is empty, but you do not also in the cycle of one by one discriminant? 10,000 data will not be judged tens of thousands of times?

If there is no query criteria, why do you have to assemble it every time?
Does adding the into OUTFILE clause in the SELECT command output directly to the file?

Filter out empty entries for incoming conditions, available Array_diff
such as $_post = Array_diff ($_post, Array ("));
Without an empty item, it's much easier to assemble SQL.

Although normal is empty, but you do not also in the cycle of one by one discriminant? 10,000 data will not be judged tens of thousands of times?

If there is no query criteria, why do you have to assemble it every time?
The add into OUTFILE clause in the SELECT directive does not output directly to the file. if (!=null) to go round to judge.


I took it all at once, because I had to generate the file in the corresponding format, so I cycled that array, like HTML, to fill in a table,tr,td or something.
If the condition is empty, then the one who does not judge whether the condition is met. No

If it is me, the same as the idea of your leadership, paging to generate ...




What's the point? He's a one-time export of all conditions related content Ah, generate a temporary file, each fetch 1000, put inside, and then finally provide the temporary file download, and finally the temporary file deleted?

Seems to be my own problem, is to download the last echo of the file will be very card, with the database is not a big relationship.

So Baidu down, in front of the echo string to join Ob_start (), in this period, echo each data, finally flush (), Ob_flush (), Ob_end_clean () all output, temporarily does not take too long time.

  • 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.