У меня есть foreach:
include('titlearray.php'); foreach ($titlearray as $index => $title) { $pos = strpos($content, $title); if ($pos !== false) { // temporarily insert a place holder in the format '#number#': $content = substr_replace($content, "##$index##", $pos, strlen($title)); } } // now play with the $title
«Titlearray.php» содержит более 50 000 значений, поэтому, когда запуск foreach выполняется, он очень медленный. Я попытался кэшировать его с использованием переходного процесса, как показано ниже:
include('titlearray.php'); //check for transient if (false === ( $title = get_transient( 'title' ) )) { foreach ($titlearray as $index => $title) { $pos = strpos($content, $title); if ($pos !== false) { // temporarily insert a place holder in the format '#number#': $content = substr_replace($content, "##$index##", $pos, strlen($title)); } } //set the transient if none set_transient( 'title', $title, 12 * HOUR_IN_SECONDS ); } // now play with the $title
вinclude('titlearray.php'); //check for transient if (false === ( $title = get_transient( 'title' ) )) { foreach ($titlearray as $index => $title) { $pos = strpos($content, $title); if ($pos !== false) { // temporarily insert a place holder in the format '#number#': $content = substr_replace($content, "##$index##", $pos, strlen($title)); } } //set the transient if none set_transient( 'title', $title, 12 * HOUR_IN_SECONDS ); } // now play with the $title
Но это не работает? Итак, как я должен кэшировать этот процессор, потребляющий foreach?