In php, use the preg_match_all () Regular Expression to check the legality of a string of about KB.

Source: Internet
Author: User
A string of about KB, which is a number + delimiter. Because it is submitted by the user, check whether it is legal. Here, I use preg_match_all + Regular Expression to detect strings. When strings are short, they can be detected. No problem occurs. When strings exceed kb, nginx will be 502. I also found the problem... A string of about KB, which is a number + delimiter. Because it is submitted by the user, check whether it is legal. I use preg_match_all + Regular Expression to detect short strings. It can be checked. No problem occurs. When the string exceeds 502 KB, nginx will be
I also found the problem, and set the Backtracking value in pcre.
Later, based on the solution provided on the internet

ini_set("pcre.backtrack_limit",1000000);

Still 502
The regular code is:

/^(\d{5}(&|$)){1,}$/

The string format is:

12345&12346&12347&……99999

Is there any other way to solve this problem?
Or where is my configuration incorrect?

Reply content:

A string of about KB, which is a number + delimiter. Because it is submitted by the user, check whether it is legal. I use preg_match_all + Regular Expression to detect short strings. It can be checked. No problem occurs. When the string exceeds 502 KB, nginx will be
I also found the problem, and set the Backtracking value in pcre.
Later, based on the solution provided on the internet

ini_set("pcre.backtrack_limit",1000000);

Still 502
The regular code is:

/^(\d{5}(&|$)){1,}$/

The string format is:

12345&12346&12347&……99999

Is there any other way to solve this problem?
Or where is my configuration incorrect?

Even ifpcre.backtrack_limitIt is still possible to crash, because a huge rollback may result in stack explosion, which is a system-level restriction,PHPOr left or right. We recommend that you use other methods to process the content. For example, split the content first and check each segment in a loop.

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.