Custom punctuation function making script run over the php's 60s runtime limit
Posted
by
webmasters
on Stack Overflow
See other posts from Stack Overflow
or by webmasters
Published on 2012-10-17T16:57:57Z
Indexed on
2012/10/17
17:00 UTC
Read the original article
Hit count: 151
php
I am importing allot of product data from an XML file (about 5000 products). When I run the script I can make it work in about 10-12 seconds.
Now, when I add this punctuation function which makes sure each product description ends with a punctuation sign, the code runs until the php 60 seconds loadtime on my server but I'm not getting any errors. I have error reporting turned on. I just get a final error that the script could not load in 60 seconds.
The question is, looking at this function, is it that resource consuming? What can I do to make it faster?
function punctuation($string){
if(strlen($string) > 5){
// Get $last_char
$desired_punctuation = array(".",",","?","!");
$last_char = substr($string, -1);
// Check if $last_char is in the $desired_punctuation array
if(!in_array($last_char, $desired_punctuation)){
// strip the $mytrim string and get only letters at the end;
while(!preg_match("/^[a-zA-Z]$/", $last_char)){
$string = substr($string, 0, -1);
$last_char = substr($string, -1);
}
// add "." to the string
$string .= '.';
}
}
return $string;
}
If the function is ok, the long runtime must come from something else which I'll have to discover.
I just want your input on this part.
© Stack Overflow or respective owner