Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeigniter: load Views progressively
    primarykey
    data
    text
    <p>I moved my scraping/parsing PHP code to Codeigniter recently. It uses <em>cURL</em> and <em>SimpleHtmlDom</em> class to retrieve data from the target URL which is later processed by the model functions several other libraries.</p> <p>There are <strong>several requests to external Webs and APIs</strong> so the original PHP script took <strong>up to 20 seconds</strong> to load the complete page, but <strong>it was OK</strong> because the PHP was split into several blocks and while the processes lower down were running the page was already rendering HTML, which could be read by the user while the rest of the data was being processed and displayed.</p> <p>The problem with switching to Codeigniter is that <strong>no HTML is rendered until the Controller script has been executed completely</strong>, even if the data processes are split into blocks and loaded by separate Views.</p> <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class HomePage extends CI_Controller { public function index() { $this-&gt;load-&gt;library('simple_html_dom'); $this-&gt;load-&gt;library('library1'); $this-&gt;load-&gt;library('library2'); $this-&gt;load-&gt;library('library3'); $this-&gt;load-&gt;model('HomePage_model'); $this-&gt;load-&gt;view('templates/header'); $targeturl = 'http://www.example.com'; $variable1 = library1::method1($targeturl); $variable2 = $this-&gt;HomePage_model-&gt;method2($targeturl); $data1 = array('variable1' =&gt; $variable1, 'variable2' =&gt; $variable2); $this-&gt;load-&gt;view('first_set_of_data', $data1); $variable3 = library2::method2($targeturl); $variable4 = $this-&gt;HomePage_model-&gt;method3($targeturl); $data2 = array('variable3' =&gt; $variable3, 'variable4' =&gt; $variable4); $this-&gt;load-&gt;view('second_set_of_data', $data2); $curlinfo = $this-&gt;HomePage_model-&gt;cURLmethod($targeturl); $data3 = array('curlinfo' =&gt; $curlinfo); $this-&gt;load-&gt;view('third_set_of_data', $data3); $this-&gt;load-&gt;view('sidebar'); $this-&gt;load-&gt;view('templates/footer'); } } /* End of file homepage.php */ /* Location: ./application/controllers/homepage.php */ </code></pre> <p>I'm not trying to optimize my code so it runs faster, it's already been revised several times... what I'm trying to do is to <strong>load Views progressively</strong> as the data corresponding to each View is ready, while the data for the other Views is being processed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload