PHP Batch Processing Big Data Processing for a long time

Source: Internet
Author: User

Recently I was writing something in PHP, because I want to read the image name in the database, access the corresponding image, read the image size and resolution, and store it in the database again. Currently, 5000 data records are processed. If no setting is added, the maximum execution time of php is 30 seconds by default.

Therefore, within 30 seconds, I can only process 700 records. At the beginning, I can only manually execute seven hundred or seven hundred records. Later, I felt that I could not do this. In the future, the amount of data would exceed, so that I would be exhausted.

There are three processing methods for searching online.

First

Directly, since you have 30 seconds by default, I will set your default time to a long point, or there is no limit.

Add in php, php ini_set ('max _ execution_time ', '000000'); the function is enough. 100 represents 100 seconds. If you set 0, therefore, there is no restriction. (Ps: I use zend combination. When it is set to 0, it is about 120 instead of no limit. My solution is, set this value to so big)


Second

I like it very much. It is the combination of php and batch processing.


[Php]
@ REM <? Php
@ REM ='
@ Set phpcli = "D: \ Program Files \ Zend Studio-8.0.1 \ plugins \ org. zend. php. debug. debugger. win32.x86 _ 5.3.18.v20110322 \ resources \ php53 \ php.exe"
@ Rem phpcli: set the path of your php.exe.
@ % PHPCLI % 0
@ Goto: EOF
@ REM ';?>
<? Php
Include 'C: \ Program Files \ Zend \ Apache2 \ htdocs \ pic_gather \ pic_operate.php ';
Echo "\ rfinish ";
Ob_flush ();
Exec ("pause ");
?>

It was a batch processing command, so I spent an hour reading the next batch processing command. Roughly translate the above program.

@: The subsequent commands are not displayed. If the command is removed, the command is printed in the Command window.

REM is the comment of batch processing, followed by the comment, not executed. Unlike @, @ only indicates that the command is not printed and does not indicate annotations.


The program starts to run. The first step is to run bat.

[Php]
@ Set phpcli = "D: \ Program Files \ Zend Studio-8.0.1 \ plugins \ org. zend. php. debug. debugger. win32.x86 _ 5.3.18.v20110322 \ resources \ php53 \ php.exe"
Set the PHPCLI Value
[Php] view plaincopy
@ % PHPCLI % <span style = "font-family: Arial, Helvetica, sans-serif;"> 0 </span>
% PHPCLI % indicates the setting of your website. php.exe is executed here, and % 0 indicates the path of the. bat file, and php.exe is used to run the. bat file.

Php does not consider REM as a comment, but a common character.

Print @ REM first, and then

[Php]
<? Php
@ REM ='
@ Set phpcli = "D: \ Program Files \ Zend Studio-8.0.1 \ plugins \ org. zend. php. debug. debugger. win32.x86 _ 5.3.18.v20110322 \ resources \ php53 \ php.exe"
@ Rem phpcli: set the path of your php.exe.
@ % PHPCLI % 0
@ Goto: EOF
@ REM ';?>
Now, php.exe can recognize it, indicating the above meaning? @ In php, do you know? This indicates the suppression error. The content in the string ''is equal to or equal to REM, so there is a @ suppression error. Enron spent.

Go to the next section

[Php]
<? Php
Include 'C: \ Program Files \ Zend \ Apache2 \ htdocs \ pic_gather \ pic_operate.php ';
Echo "\ rfinish ";
Ob_flush ();
Exec ("pause ");
?>
Here is the program you want to execute. I don't want to write it here, so I just need to include it so that. bat can easily become a template.

By now, your php.exe is finished, but it is not finished yet. The batchcompute command has just arrived.

[Php]
@ % PHPCLI % 0
Then, in order not to let the batch processing command not know the php language

[Php]
@ Goto: EOF
To end the program.
Someone asked why this is not the case:

[Php]
@ Set phpcli = "D: \ Program Files \ Zend Studio-8.0.1 \ plugins \ org. zend. php. debug. debugger. win32.x86 _ 5.3.18.v20110322 \ resources \ php53 \ php.exe"
@ REM PHPCLI
@ % PHPCLI % 0
@ Goto: EOF
 
<? Php
Include 'C: \ Program Files \ Zend \ Apache2 \ htdocs \ pic_gather \ pic_operate.php ';
Echo "\ rfinish ";
Ob_flush ();
Exec ("pause ");
?>
You don't have to make it so complicated. I also tried it,

The command line in cmd is found to be:

@ Set phpcli = "D: \ Program Files \ Zend Studio-8.0.1 \ plugins \ org. zend. php. debu
G. debugger. win32.x86 _ 5.3.18.v20110322 \ resources \ php53 \ php.exe"
@ REM PHPCLI
@ % PHPCLI % 0
@ Goto: EOF

The original author of this Code is trying to avoid this situation and print too much junk information.

So this is the original author's Incisive Point.

Third

If you only need to update the string information, for example, you have set the class. If the class is 'natural view', add pic_gather/nature/image to the front of the image. So there is no need to use such complex things as above, just use the SQL language directly, and the concat () function has such a function.

Author: wolinxuebin

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.