I've just released the first version of a WordPress plugin I wrote, and I've received a report that at least one of the people using my plugin is receiving an execution timeout error citing this block of code:
function getNumericAttributeFromHTML($htmlElement, $attribute){
$attrStartPos = stripos($htmlElement, $attribute) + strlen($attribute);
$strOffset = 0;
$searchWithin = substr($htmlElement, $attrStartPos);
while(!(is_numeric($searchWithin[$strOffset]))){
$strOffset++;
}
$attrStartPos += $strOffset;
$strOffset = 0;
$searchWithin = substr($htmlElement, $attrStartPos);
while((is_numeric($searchWithin[$strOffset]))){
$strOffset++;
}
return substr($htmlElement, $attrStartPos, $strOffset);
}
This function is called twice per image on the page. Am I being crazy inefficient, or is it possible their host is just terrible?
Thanks in advance for any help you can provide.
while(!(is_numeric($searchWithin[$strOffset]))) will run infinte times if $searchWithin has no numeric character!
Note the problem might be somewhere else.
To pinpoint the actual problem I suggest you get the reproducible steps from the bug and use a profiler to profile the code. You'll surely find where the problem is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With