JQuery Masonry with Zend_Paginator

When I use jQuery Masonry Infinite Scroll with  Zend_Paginator, I found that the last page apper over and over again in spite of 2 pages.

According to Lukas White,  we have to return "404 not found" when page number is greater than the maximum page number.

So I tried below.

 

if($this->getRequest()->getParam('page') > $paginator->count()) {
    $this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');exit;
}

It worked fine I expected!