Multi-Threading in Laravel
<p>I am running into a problem where my database calls are slowing up the page load significantly. I am populating multiple charts from elections data, and my table contains around 1 million rows, and I have to query this data multiple times in each methods inside the <code>getCharts()</code> method.</p>

<p>I'am <a href="https://github.com/laracasts/PHP-Vars-To-Js-Transformer" rel="nofollow noreferrer">using this</a> to pass the return data to JavaScript. </p>

<p>These charts gets re-populated when you click on a data point. So if you click on a point i.e ('democrat) it will reload the page and call these methods again.</p>

<p>What I am asking is wether it is possible to do something like this in native PHP. The server is running PHP 5.2 on linode. </p>

<pre><code>foreach(function in getChartsMethod){
     Start a child thread to process the function. 
}  
join the threads. 
reload the page. 


public function getCharts(){
        $this-&gt;get_cast_chart();
        $this-&gt;get_party_chart();
        $this-&gt;get_gender_chart();
        $this-&gt;get_age_chart();
        $this-&gt;get_race_chart();
        $this-&gt;get_ballot_chart();
        $this-&gt;get_county_chart();
        $this-&gt;get_precinct_chart();
        $this-&gt;get_congressional_district_chart();
        $this-&gt;get_senate_district_chart();
        $this-&gt;get_house_district_chart();
        return view('elections.index');
    }
</code></pre>

<p>Sample method </p>

<pre><code>public function get_party_chart(){
        $query = DB::table($this-&gt;tableName)
            -&gt;select('party', DB::raw('count(*) as numVotes'))
            -&gt;groupBy('party')
            -&gt;orderBy('numVotes', 'ASC');

        if ($this-&gt;filterParameters != null){
            $query = $query-&gt;where(key($this-&gt;filterParameters), $this-&gt;operator, current($this-&gt;filterParameters));
        }
        $chartData = $query-&gt;get();
        $chartData = $this-&gt;prepare_data_for_chart($chartData, 'party', 'numVotes');
        JavaScript::put(['partyChart' =&gt; $chartData]);

    }
</code></pre>