Same topics as:
-
PHx not running when content is bigger than a certain limit?
-
Extended placeholders not interpreted
AjaxSearch use Phx to set up the display of results. Unfortunately when the number of results is important the placeholders are broken and the display wrong ... Like this:
[+as.noResults:is=`1`:then=`
`:else=`
Since several months i have discovered this issue and I didn’t understand why ...
Now I have the proof of the limitation of the Modx Parser. This limitation comes from the PHP "
preg_match_all" order.
Here is a simple test (extracted from the ajaxResults template):
[+as.noResults:is=`1`:then=`
<div class="[+as.noResultClass+]">[+as.noResultText+]</div>
`:else=`
<p class="AS_ajax_resultsInfo">[+as.resultInfoText+]</p>
[+as.listGrpResults+]
`+]
This is a very simple test. If noResults=0 you display the results (as.resultsInfoText and aslistGrpResults)
On my laptop (XP, Php 5.3, php memory_limit = 32Mb) this test is correct until the size of the results is <
32kb 64 Kb (255 lines of 128 characters * 2 bytes).
If the results reach the size of 32 kb (256 lines of 128 characters), the placeholders are broken.
Find enclosed a small code to demonstrate this limitation. Look at the code. This test is done by calling the MODx parser (
assets/plugin/phx class).
<?php
// Test of Phx by Coroico ([email protected])
Define('LINE128','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$tpl = <<<EOD
[+as.noResults:is=`1`:then=`
<div class="[+as.noResultClass+]">[+as.noResultText+]</div>
`:else=`
<p class="AS_ajax_resultsInfo">[+as.resultInfoText+]</p>
[+as.listGrpResults+]
`+]
EOD;
// Setup the MODx API
define('MODX_API_MODE', true);
include_once('index.php');
$modx->db->connect();
$modx->getSettings();
global $modx;
include_once('assets/plugins/phx/phx.parser.class.inc.php');
?>
<div >
<FORM method='POST'>
Nb lines: <INPUT type='text' name="nbr" value="" />
<INPUT type="submit" name="sub" value="GO" />
</FORM>
</div>
<?php
if ($_POST['nbr']) {
$nbr = (int) $_POST['nbr']; // nb of results
$nbc = $nbr*128*2; // nb bytes
$size = $nbc/1024; // in Kb
$size = $size."kb";
if (class_exists('PHxParser')) {
$varResults = array();
for($i=0;$i<$nbr;$i++) $listGrpResults .= LINE128 ."\n\r";
$phx = new PHxParser($tpl);
$phx->setPHxVariable('as.listGrpResults',$listGrpResults); //[+as.listGrpResults+]
$resultInfoText = $nbr.' lines ('.$nbc.' characters) displayed. size='.$size;
$phx->setPHxVariable('as.resultInfoText',$resultInfoText); // [+as.resultInfoText+]
$phx->setPHxVariable('as.noResults',0); // [+as.noResults+]
$output = $phx->parse($tpl) . "\n";
echo $output;
return;
}
}
?>
Copy/paste the above code in a testPhx.php file and execute this file at the root of your Modx environment.
Then enter a value of 255 and see the results (255 lines of xxx should be displayed).
Do the same with 256 lines and see how the placerholders are broken.
May be the limits could be different on your environment. On my latop the limit is between 255 and 256.
I found
this article about a similar issue. I haven’t still tried to increase the pcre.recursion_limit (see
http://docs.php.net/manual/en/pcre.configuration.php). This solution seems a bit dangerous.
So i think that I will simply reorganise the display of AjaxSearch differently in order to avoid to use the parser to concatenate the results to the layout template
Hope this post help to explain some issues with phx and large volume of data.