2

I'm trying to add threading to a web resource in an attempt to speed it up a bit. Everything is running properly 1/3 of the time. The other 2/3 result in either

net::ERR_INCOMPLETE_CHUNKED_ENCODING 

or

net::ERR_EMPTY_RESPONSE

This happens in Chrome (and a similar error with wget), but FireFox and IE run properly.

The page loads fine when it is run not threaded 100% of the time, however as soon as I reference the pthreads library things do not run as smoothly

The only code changes I am preforming are this:

$aTaskBox = $this->getTaskBox($sUsername, $aTask);
// If the returned task box is not really a task box but a boolean FALSE,
// the task is not to be displayed.  If it is not FALSE, then assume it is
// really a task box and add it to the HTML array.
if ($aTaskBox !== FALSE) {

    $aSectionHTML[$aTaskBox["sCategory"]] .= $aTaskBox["sHTML"];
}

to this:

$tdThread = new TaskBoxThread($this, $sUsername, $aTask, FALSE, FALSE);
$tdThread->start();
$aThreads[] = $tdThread;
...Code emitted...
//Wait for all of threads to finish, and collect the data from them
foreach($aThreads as $tdThread){

    $tdThread->join();
    if($tdThread->sCategory != "Complete"){
        $aSectionHTML[$tdThread->sCategory] .= $tdThread->sHTML;
    }
}

And my thread class:

class TaskBoxThread extends Thread {
    public $sHTML = "";
    //set the category to a defualt value so that errors are not generated later on
    public $sCategory = "Complete";

    public function __construct($oHeadquarters, $sUsername, $aTask, $bCurrentlyInList, $bForProjectView){

        $this->oHeadquarters = $oHeadquarters;
        $this->sUsername = $sUsername;
        $this->aTask = $aTask;
        $this->bCurrentlyInList = $bCurrentlyInList;
        $this->bForProjectView = $bForProjectView;
    }

    public function run(){
        $aBox = $this->oHeadquarters->getTaskBox($this->sUsername, $this->aTask, $this->bCurrentlyInList, $this->bForProjectView);

        // If the returned task box is not really a task box but a boolean FALSE,
        // the task is not to be displayed.  If it is not FALSE, then assume it is
        // really a task box and add it to the HTML array.
        if($aBox != FALSE){

            $this->sCategory = $aBox["sCategory"];
            $this->sHTML = $aBox["sHTML"];
        }
    }
}

Code wise, there doesn't seem to be anything that could be causing the issue, so I tried to grab the page with wget, and this also fails with a byte read error on the very last byte, which would indicate the last byte being sent is not zero as per the chunked encoding spec, however when I look at the packets with wireshark, everything is terminated properly.

I'm at a complete loss of what to try next, and I've scoured the web, so what is another direction of things on the server that may be causing this issue that I can look into?

Edit: I thought I'd take another look at the code, and when I comment out:

$aBox = $this->oHeadquarters->getTaskBox($this->sUsername, $this->aTask, $this->bCurrentlyInList, $this->bForProjectView);

it runs perfectly, and as such I tried to debug that function. I ended up commenting out the ENTIRE function and simply

$aTaskBox["sHTML"] = "<div>Hi there.</div>";
$aTaskBox["sCategory"] = "WIP";

This is a trivial function, and yet the error still occurs, this leads me to believe the error has something to do with the actual function call.

TheBat
  • 1,006
  • 7
  • 25

0 Answers0