Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DX] Promote phppm and add support for resettable services #23984

Copy link
Copy link
Closed
@zmitic

Description

@zmitic
Issue body actions
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version 3.3.x

Intro

phppm is a library that makes php application run 10-15 times faster compared to ./bin console server:run. And unlike internal php web server, phppm supports concurrent requests which makes developing angular state machines much faster.

Problem

Because services are shared between requests, any memoized data can/will affect next request. Doctrine identity map is the best example but it is easy solvable; only do $em->clear() in kernel.terminate.

I am using it for about a month and so far, I spotted only 2 problems. One is data collectors but it a problem only in debug mode so not something of big relevance.

The second is EntityType service. It has very nice optimization of queries but keeps results in $choiceLoaders property. Parent class DoctrineType takes care of it, check the code.

This creates 2 problems when used in phppm enviroment, first one is described here but closed in favor of this ticket. The second problem is that memory will keep pilling up for every form with EntityType and it cannot be solved using DTO objects.

The solution

It should be pretty easy to solve it. I made a bundle that will collect all services with ResettableServiceInterface implemented and call reset() when kernel.terminate event is triggered.

So for example, if this RFC is accepted, DoctrineType would only have this extra code:

abstract class DoctrineType extends AbstractType implements ResettableServiceInterface
{
    public function reset()
    {
        $this->choiceLoaders = [];
    }
}

Any other service that does memoization can be easily upgraded to work with phppm.

Proposal

Symfony already promotes popular bundles and while phppm is not technically a bundle, I think it should be placed there. I am willing to write docs for that.

This solution should be part of core, not a third-party bundle. More people will adopt it that way because not all developers are familiar with phppm but also because it is part of core and people prefer opinionated solutions.

Technical

You guys are far more skilled than me but if you check my code and think it is good enough, I could make a PR. Please keep in mind that would be my first contribution so be gentle 😄

I would suggest one more thing, the new config value:

framework:
    phppm: false

If false, than services would not be reset to avoid instantiating them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DXDX = Developer eXperience (anything that improves the experience of using Symfony)DX = Developer eXperience (anything that improves the experience of using Symfony)Feature

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.