Symfony subrequests and Sulu PHPCR session scope across ESI fragments
0 reputation · 21 Jan 2025, 16:22 UTC
0 reputation · 21 Jan 2025, 16:22 UTC
Sulu persists localized page content through Doctrine PHPCR-ODM while Symfony handles the HTTP request lifecycle. The integration boundary is unclear when Symfony creates subrequests or renders ESI fragments: whether the PHPCR session opened for the parent request remains valid and consistent for nested content reads or writes, or whether each subrequest must open and flush its own session before the parent response completes.
Because PHPCR changes are rolled back at request end if not flushed, and because Jackalope-Jackrabbit and Jackalope-Doctrine-DBAL expose different locking and concurrency guarantees, reusing one session across fragments risks stale reads or lost updates. Sulu version differences between 1.x and 2.x also affect bundle registration and session factory tagging.
35275 reputation · 21 Jan 2025, 19:05 UTC
Do not give Symfony render/forward subrequests their own PHPCR session by default. They normally share the parent request-scoped PHPCR session and DocumentManager. Real ESI fragments are separate HTTP requests, so each fragment request opens its own session. Reusing one session across subrequests is safe for reads but unsafe for writes unless you control flush ordering, because subrequests share one UnitOfWork, one identity map, and one flush point.
render or forward see the same session object.esi:include triggers a new sub-request through the HttpKernel, which bootstraps its own container services and therefore its own PHPCR session.render/forward subrequests or ESI include sub-requests. This is the diagnostic that changes the recommendation.Compare spl_object_id() of the PHPCR Session or DocumentManager in the parent controller and inside a subrequest. Identical identifiers indicate a shared request-scoped session. For ESI, call the fragment URL directly and confirm it initializes a separate session.
This answer assumes Sulu’s PHPCR session is request-scoped in your installed version; that is version-sensitive and should be confirmed in the running application. Jackalope conflict exception names are illustrative backend behavior, not guaranteed error codes for your deployment. Treat the Sulu 1.x versus 2.x service-ID differences as unverified until you inspect the container.
Missing diagnostic detail: Are your fragments Symfony subrequests or ESI sub-requests? The answer determines whether you share one session or provision one per fragment.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.