PHP batch processing Big Data long time processing _php tutorial

Source: Internet
Author: User
Recently doing a thing, written in PHP, because the database to read the name of the picture, and then access to the corresponding image, read the size of the picture and resolution, re-deposited into the database. The amount of data is now 5,000, and if not set, the default maximum execution time for PHP is 30 seconds.

So in 30 seconds, I can only handle 700, just start manually, 700, 700 of the execution. Later, I feel that this will not work, the amount of data will be over 10W, it would be exhausting me.

Online search for the next, there are three ways to deal with.

First Kind

Very direct, since you default 30 seconds, then I will set your default time long, or directly without restrictions.

Add in PHP, PHP ini_set (' max_execution_time ', ' 100 '), function is available, 100 for 100 seconds, if you set 0, then there is no limit. (PS: I use the combination of Zend, set to 0, not without limits, but about 120 looks, my solution is to set this value so big)


The second Kind

I like it, is to use the combination of PHP and batch processing.


[PHP]
@REM @REM = = '
@SET phpcli= "D:\Program files\zend\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 ';? >
Include ' C:\\Program files\\zend\\apache2\\htdocs\\pic_gather\\pic_operate.php ';
echo "\rfinish";
Ob_flush ();
EXEC ("pause");
?>

is a batch command, so I spent 1 hours specifically looking at the next batch of commands. The above procedure is generally translated.

@: does not show the following instructions, if removed, the command will be printed in the Commands window

REM is a batch comment, followed by a comment, not executed. Unlike @, the @ is just a command that doesn't print and does not indicate a comment.


The program begins execution, first the bat runs

[PHP]
@SET phpcli= "D:\Program files\zend\zend studio-8.0.1\plugins\org.zend.php.debug.debugger.win32.x86_5.3.18. V20110322\resources\php53\php.exe "
Set the value of the PHPCLI
[PHP] View plaincopy
@%phpcli%%0
%phpcli% represents the path you set above, which means execute php.exe, and then% 0 represents the path where this. bat file is located, connected by running the. bat file with Php.exe.

There is a phenomenon like this, PHP does not think that REM is a comment, it is only a normal character.

You print @rem first, and then

[PHP]
@REM = = '
@SET phpcli= "D:\Program files\zend\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 ';? >
Here, Php.exe, do you know what it means? In PHP @ Can you know? This expression suppresses the error, then the content in the string "is" = = with REM, then there is an @ suppression error. Enron spent.

Go to the next section

[PHP]
Include ' C:\\Program files\\zend\\apache2\\htdocs\\pic_gather\\pic_operate.php ';
echo "\rfinish";
Ob_flush ();
EXEC ("pause");
?>
This is the program you are going to execute. I don't want to write about it, so include it so it's easy for. bat to become a template.

Your php.exe is gone, but it's not over yet, just a batch of orders to

[PHP]
@%phpcli%%0
After that, in order not to let the batch command not recognize the PHP language,

[PHP]
@goto: EOF
To end the program.
Someone asked why not just this:

[PHP]
@SET phpcli= "D:\Program files\zend\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

Include ' C:\\Program files\\zend\\apache2\\htdocs\\pic_gather\\pic_operate.php ';
echo "\rfinish";
Ob_flush ();
EXEC ("pause");
?>
Don't make it so complicated, I tried it,

The Discovery cmd command line appears:

@SET phpcli= "D:\Program files\zend\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 wants to avoid this situation and print out too much junk information.

So that is the original author of the brilliant point ah.

Third Kind

If you, just update the string information inside, such as you set the class, if class= ' natural scenery ', then put the image in front of the pic_gather/nature/image. Then there is no need to use the above complex things, directly in the SQL language, the concat () function has such a function.

Author: wolinxuebin

http://www.bkjia.com/PHPjc/478115.html www.bkjia.com true http://www.bkjia.com/PHPjc/478115.html techarticle recently doing a thing, written in PHP, because the database to read the name of the picture, and then access to the corresponding image, read the size of the picture and resolution, re-deposited into the database. ...

  • Related Article

    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.