Polling
Refresh a server-side table at a fixed interval, and when to prefer Mercure
poll() reloads a table’s Ajax source on a timer. Paging, search, and ordering are kept, so the
viewer stays where they were.
use App\Entity\Order;
use Pentiminax\UX\DataTables\Attribute\AsDataTable;
use Pentiminax\UX\DataTables\Column\TextColumn;
use Pentiminax\UX\DataTables\Model\AbstractDataTable;
use Pentiminax\UX\DataTables\Model\DataTable;
#[AsDataTable(Order::class)]
final class OrdersDataTable extends AbstractDataTable
{
public function configureDataTable(DataTable $table): DataTable
{
return $table
->serverSide()
->poll('30s');
}
}
Intervals
poll() accepts a number of seconds (30) or a duration string: '10s', '1m', or '1h'. The
minimum is 2 seconds and the maximum is 24 hours. A value outside that range, or a malformed one, throws an InvalidArgumentException.
Requirements
Polling needs a table that fetches rows over Ajax: a server-side table, an ajax() source, or an
API Platform table. Rendering a table that has no ajax option once the bundle has prepared it
throws a LogicException, because it has nothing to reload. This includes an application that sets
the Ajax source only from JavaScript before the controller connects: declare the source in PHP.
When the Timer Pauses
A tick is skipped, not queued, while:
- the browser tab is hidden. When it becomes visible again, the table reloads immediately if the interval has elapsed.
- an edit or confirmation modal is open.
- a detail (child) row is open in the table, so it is not collapsed under the viewer.
- a previous request is still in flight, so requests never overlap.
- the viewer is typing in the search field.
The timer stops when the table is removed from the page and restarts when Turbo restores it.
Polling or Mercure
| Polling | Mercure | |
|---|---|---|
| Setup | One method call | Hub, topics, and publishers |
| Freshness | Up to one interval late | Near real time |
| Server load | One request per viewer per tick | One request per viewer per change |
| Works behind proxies | Everywhere | Needs long-lived SSE connections |
Choose polling for data that changes continuously or from outside your application, such as metrics or queue sizes. Choose Mercure when your application knows when a row changes. Enabling both works, but the table then reloads for every push and every tick, so the browser logs a console warning once.
Every tick hits the Ajax endpoint. Keep the interval as long as the data allows.