0

Why would un-commenting the last line in this code cause a fatal error

$html = phpQuery::newDocumentHTML($social_icons_block);

$html->find('.managed-form')->remove();
$html->find('.drag-handle')->parent()->remove();
$html->find('.set-social-icons')->parent()->remove();
//$html->find('.pull-left-space')->remove();

Error is

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20 bytes) in /Applications/AMPPS/www/startup/assets/classes/phpQuery/phpQuery/phpQueryObject.php on line 3069

The html is

<div class="managed-form">
    <div class="wrp">
        <h3>Social Icons</h3>
        <div name="set-social-icons" complex-input="set" template=".set-social-icons"></div>
    </div>
</div>

<div class="set-social-icons row">
    <div class="pull-left">
        <div class="drag-handle">&#8645;</div>
    </div>
    <div class="pull-left-space">
            <select name="social-icon" class="inputBox-xsmall">
                <option value="facebook">Facebook</option>
                <option value="linkedin">LinkedIn</option>
                <option value="twitter">Twitter</option>
                <option value="youtube">Youtube</option>
                <option value="instagram">Instagram</option>
                <option value="pinterest">Pinterest</option>
                <option value="google-plus">Google Plus</option>
                <option value="rss">RSS</option>
            </select>
    </div>
    <div class="pull-left-space link-outer">
        <input name="link" class="inputBox inputBox-small" placeholder="Link To"/>
    </div>
    <div class="pull-left-space">
        <input type="button" class="add-row" value="+" />
        <input type="button" class="delete-row" value="-" />
    </div>
</div>

Adding echo memory_get_usage(); before the commented line gives 4517876. Memory is set to 128M

orbitory
  • 1,090
  • 5
  • 16
  • 40
  • 3
    Possible duplicate of [Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)](http://stackoverflow.com/questions/561066/fatal-error-allowed-memory-size-of-134217728-bytes-exhausted-codeigniter-xml) – skrilled Mar 25 '16 at 00:23
  • That one is not about phpQuery library. – orbitory Mar 25 '16 at 00:24
  • 2
    All Allowed Memory Size errors are the same. What they used to get the same error as you is irrelevant. – skrilled Mar 25 '16 at 00:24
  • I agree but that is not why I asked the question. – orbitory Mar 25 '16 at 00:26
  • 1
    Also your script dies at `/Applications/AMPPS/www/startup/assets/classes/phpQuery/phpQuery/phpQueryObject.php` so looking at anything but line 3069 of this file is looking at something that has nothing to do with the error. Unless you plan on rewriting this library, or fixing this library, any answer on the question I flagged this as a duplicate thereof applies. And that's why I flagged it :p – skrilled Mar 25 '16 at 00:27

1 Answers1

0

In this specific case, it turns out my selectors were not properly set up

'.set-social-icons' parent doesn't exist, there is no parent as you can see from the html. So I think the code removes all html and the second next line tries to remove something from an empty document.

Maybe getNodeXpath function breaks when the html in the variable doesn't exist

Thank you

orbitory
  • 1,090
  • 5
  • 16
  • 40