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.
You have an infinite
whileloop. You’re just incrementing the value of$strOffsetwithout changing the value of$searchWithin[$strOffset]so if it’s not numeric, it never will be and will get stuck looping forever.