actually on further thought you can’t do option 1 above just like that, as the cache.php needs to be updated from the new browscap.ini… does not seem that easy to trigger… I have:
global $browscap;
$browscap->localFile = WP_PLUGIN_DIR.'/php-browser-detection/cache/php_browscap.ini';
$browscap->updateCache();
exit;
but it crashes at this line (of all places?) in _getRemoteIniFile
$browscap = explode("\n", $browscap);
perhaps this is the memory usage issue talked about..? it is a rather big file to split like that. so I’d like to propose some alternatives…
1. use substr instead of explode… as content variable gets bigger, browscap variable gets smaller the, saving memory…
// $browscap = explode("\n", $browscap);
$pattern = self::REGEX_DELIMITER . '(' . self::VALUES_TO_QUOTE . ')="?([^"]*)"?$' . self::REGEX_DELIMITER;
if (strstr($browscap,"\n")) {
while (strstr($browscap,"\n")) {
$pos = strpos($browscap,"\n");
$subject = trim(substr($browscap,0,$pos));
$content .= preg_replace($pattern, '$1="$2"', $subject)."\n";
$browscap = substr($browscap,($pos+1));
}
if ($browscap != '') {
$subject = trim($browscap);
$content .= preg_replace($pattern, '$1="$2"', $subject)."\n";
}
} else {throw new Exception("No lines found.");}
2. change the _getRemoteData function to write the file contents to a file, and then use fgets on the local file to retrieve it line by line…
$pattern = self::REGEX_DELIMITER . '(' . self::VALUES_TO_QUOTE . ')="?([^"]*)"?$' . self::REGEX_DELIMITER;
$content = '';
$fh = fopen($url,'r');
while (!feof($fh)) {
$subject = trim(fgets($fh));
$content .= preg_replace($pattern, '$1="$2"', $subject) . "\n";
}
if (!file_put_contents($path, $content)) {
throw new Exception("Could not write .ini content to $path");
}
the first example seems rather slow, but it does finish eventually. the second seems much faster but I’m not totally sure if the end result is the same or not (and again only works for local file source at the moment.)
either way I’m stuck here for now… as the resulting prepared file is still not processed into a working cache.php file for reasons unknown as yet… in any case I hope this input helps resolve the memory issue.