So I'm going ahead and reviving an old thread here since this is an old issue for me that I've been working around for a while, but I spent some time today trying to understand what the cause was exactly and wanted to share with others what I found out about what the true issue actually is.
As mentioned in my previous reply below, I ended up modifying the default Joomla System SEF Plugin to increase the PCRE Recursion/Backtrack Limits on the fly if possible, in order to avoid the "White Screen of Death" issue that would be caused when the plugin was enabled back when I originally encountered the issue with Joomla 1.5 when a lot of data was being output on the screen, particularly when using the content plugin I had developed, since it generated a lot of HTML to be displayed on the page.
Newer versions of Joomla improved the situation slightly, since at least now you get an error screen due to the checkBuffer() method now in the System SEF Plugin:
private function checkBuffer($buffer) {
if ($buffer === null) {
switch (preg_last_error()) {
case PREG_BACKTRACK_LIMIT_ERROR:
$message = "PHP regular expression limit reached (pcre.backtrack_limit)";
break;
case PREG_RECURSION_LIMIT_ERROR:
$message = "PHP regular expression limit reached (pcre.recursion_limit)";
break;
case PREG_BAD_UTF8_ERROR:
$message = "Bad UTF8 passed to PCRE function";
break;
default:
$message = "Unknown PCRE error calling PCRE function";
}
JError::raiseError(500, $message);
}
}
But unfortunately, that approach doesn't really help fix the problem (for example, that doesn't help anyone trying to use my plugin because they would just get the 500 error or Exception instead of the desired output) and in my case the buffer only got messed up when the background image RegEx was run within the System SEF Plugin so I ended up creating a modified version of the System SEF Plugin with my solution and pointed my users to it if they ended up encountering the issue on their site.
I don't know if I ever created a tracker item for the issue, but I did find this existing one which was closed recently and surprisingly mentioned that the patches had been committed and were part of Joomla 3.1:
However, I examined the patches and took a look at the latest Joomla 3.1 beta2, but I don't see anything much different in the System SEF Plugin that would address the situation.
Regardless, the issue came up again today when I was about to start migrating some new changes I had made to an older version of my plugin and I decided I'd take a closer look and try and figure out what exactly caused that Background Image RegEx to die on me with the output my plugin was generating.
I tried all sorts of different things to try and figure it out, and was a bit perplexed when the following call to my plugin:
{docmanlist get_subfolders 99 1}
Would die and yet the following calls:
{docmanlist get_subfolders 99 8}
{docmanlist get_subfolders 99 7}
{docmanlist get_subfolders 99 6}
{docmanlist get_subfolders 99 5}
{docmanlist get_subfolders 99 4}
{docmanlist get_subfolders 99 3}
{docmanlist get_subfolders 99 2}
Which generated almost exactly the same output, would not.
Then I tried running my output through HTML Tidy and throwing that into a test article and trying to see if I could replicate the issue that way and found I couldn't, which is pretty similar to what Elin tried during her test in the tracker item above.
I tried a few other things too, but then I decided to go ahead and create a test file with the page output as it was right before the call to the Background Image RegEx and try and see if I could create a test case where I could replicate the issue quickly to help me figure out what the issue was.
I was successfully able to replicate the issue in this way, and then I began thinking about what the difference between the two approaches would be in terms of output and what I realized was that in the first case the entire output was being added to the page as a single, very long, string, while in the second case each call to the plugin would result in separate strings of a shorter length being added to the page. So I created a third test file and started breaking the single long line down into a shorter length and found I was able to get it process correctly right around the 104,600 characters per line mark.
So really, the issue actually is that the output I'm generating is too long to be processed correctly if the PCRE Backtrack Limit happens to be set at a lower value than the length of the string that gets generated by my plugin.
It looks like the quick fix here would be to modify how my output is generated so there are some line breaks in there, which will be easy enough now that I know what causes the issue, but generating a long output string is something that other developers could easily make the same mistake doing too so hopefully this helps others to know about.
The other side of this story, that I've also tried to clear up within my output, but which I don't have great concrete data on yet is that the more inline styles my output had, the longer the System SEF Plugin took to process the Background Image RegEx. Also, the first RegEx in the System SEF plugin, which seems to add in the base URL for your site to any src, href, and poster attributes in your output, seems to take longer to process if the more links are displayed on the page so I think I also tried to minimize that impact by including the base URL already within my output and I think allowed the RegEx below to get processed more quickly (I was doing that development/testing two weeks ago, so the memory is a little fuzzy on those two, but I was noticing multiple seconds being adding to the pageload due to the time it was taking for the output to process these two regular expressions).
$regex = '#(src|href|poster)="(?!/|'.$protocols.'|\#|\')([^"]*)"#m';
$buffer = preg_replace($regex, "$1=\"$base\$2\"", $buffer);
I've gone ahead and attached my sample test files, but here is the output that was generated on my end (if I shortened the longest line in the 3rd test file slightly, then the buffer would remain intact):
Test File 1: C:\xampp\htdocs\tests\background_image_regex/docmanlist_get_subfolders_99_0_output.txt
Test File 2: C:\xampp\htdocs\tests\background_image_regex/docmanlist_get_subfolders_99_individual_output.txt
Test File 3: C:\xampp\htdocs\tests\background_image_regex/docmanlist_get_subfolders_99_0_output_without_inline_styles.txt
Buffer is now null (processed preg_replace() in 0.036 seconds)
Buffer is intact (processed preg_replace() in 0.072 seconds)
Buffer is now null (processed preg_replace() in 0.093 seconds)
Test File 1 had total of 402 lines.
Longest line found on line 208 with 284911 characters.
Test File 2 had total of 408 lines.
Longest line found on line 209 with 49425 characters.
Test File 3 had total of 406 lines.
Longest line found on line 211 with 104619 characters.