Questions about mezzio-swoole, everytime I refresh the page, title reduplicated one more time!

Pls check this webiste http://www.mm3bb.com/

It is a brand-new skeleton, every time I refresh the home page, the title repeat one more time.
like
<title>Home - mezzio</title> 1st time visit

<title>Home - mezzio - Home - mezzio</title> 2nd time visit

<title>Home - mezzio - Home - mezzio - Home - mezzio</title> 3rd time visit

That’s ridiculous! I don’t know what’s going wrong.

Anybody can tell me why?

Most probably the problem is that the template renderer is not stateless, but keeping bits of information inside of it.

When you serve an app with php-fpm, a new process is spinned-up for every request, which makes this kind of things pass unnoticed.

However, since swoole keeps services in memory and reuses them between requests, if you append a title on every request, they can end up getting merged.

This is documented and you can find some ways to work around it here: Considerations when using Swoole - mezzio-swoole - Laminas Docs

Thanks for your kind reply! But I am not familar with the mezzio-swoole framework. The swoole-kind framework works so much different from the php-fpm kind.

I am just trying to apply mezzio-swoole to do stuff. I didn’t think about that I will encounter problems when I just install the official framework skeleton.

In my plan, I first install the official skeleton, then change it little by little, at least I can edit the view, it should be safe.

I didn’t append a title to every request, If I remove this, then the webpage have no title at all. I don’t know how to deal with this.

This is the key. Swoole is quite new and works in a fundamentally different way. You must understand that difference in order to understand why you’re seeing this behavior. You’re likely to run into it again, if you’re going to use Swoole, so I recommend studying up on that. @acelaya gave a good overview and linked to a place to get started. Php is going stateless but it’s not going to happen overnight.

The head-title view helpers use a stateful container. I normally inject a middleware that resets all of the laminas view helpers affected for every request. Head title, head link, head script etc.

Here’s a link to something a bit old that I found - it refers to the Zend equivalents.