Problem with using PHPQuery

Active3 hr before
Viewed126 times

4 Answers


Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers ,I tested phpQuery. Which looks like it has NO memory leaks. Also very very low memory usage. Only 4 kB on a file of 90 kB. So it looks like it parses real-time and does not have the document in memory. At least that is what I found, I could be wrong., Thank you very much for your hint about unloadDocuments(), my script was using so much RAM because simply unsetting didn't free up the memory, but after calling $mydom->unloadDocument() all memory is cleaned up properly. They should add a destructor to phpQuery so it does this automatically... – Tomas M Sep 19 '16 at 13:07 ,Simple HTML Dom has some memory leak problems. You have to be very carefull when you are 'cloning' object by its selector. Avoid it!

With phpQuery it is only one command which clears all, as far as I know.


Here's me answer:


$pq = phpQuery::newDocument($html);

$projects = array();
$i = 0;

foreach($pq['.project-preview'] as $work) {
   // iteration returns PLAIN dom nodes, NOT phpQuery objects
   $pqwork = pq($work);

   $projects[$i]['name'] = $pqwork['div'] - > eq(1) - > text();
   // Unfortunately pq($work)['div']->eq(1)->text(); does not work


load more v

window.$ = document.querySelector; instead of,Frontend Development » 5 Things You Should Stop Doing With jQuery,The following: (function($) { }(jQuery)); is a short cut for document ready.,The following is a short cut for document reader $(function( ) { // code })

If you are adhering to the “scripts at the bottom” best practice, then you have no need for jQuery’s document ready function as the HTML is already loaded by the time the script is run.

<p id="zack">This element is on the page <strong>BEFORE</strong> all the scripts. No document ready needed.</p>

  <script src=""></script>

  <script type="text/javascript" charset="utf-8">

    // if you include your scripts at the very bottom, you don't need document ready
    (function($) {

      $("#zack").css("color", "green");
      $("#slator").css("color", "red");



<p id="slater">This element comes after the scripts and won't be available.</p>
load more v

The easiest way to give Babel a try is to use the online version, which allows you to enter your source code on the left, and outputs a transpiled version on the right.,Note: Again, there are many different ways to make use of the different polyfills you will encounter — consult each polyfill's individual documentation.,When poor-quality browser-sniffing code, feature-detection code, and vendor prefix usage block browsers from running code they could otherwise use just fine.,To avoid loading more JavaScript than you need, bundle your scripts into a single file using a solution like Browserify. In general, reducing the number of HTTP requests is very good for performance.

npm install - g jshint
load more v

Already on GitHub? Sign in to your account ,By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails., Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community. , Why GitHub? Features → Mobile → Actions → Codespaces → Packages → Security → Code review → Issues → Integrations → GitHub Sponsors → Customer stories →

load more v

Other "problem-using" queries related to "Problem with using PHPQuery"