Home >Backend Development >PHP Tutorial >Why can't the global array be used in swoole's event callback function?

Why can't the global array be used in swoole's event callback function?

WBOY
WBOYOriginal
2016-08-18 09:16:261335browse

Why can't the global array be used in swoole's event callback function?

Why can't the global array be used in swoole's event callback function?

As shown in the figure, the array explicitly declared in the top-level scope cannot be called in the callback function of the onmessage event. Each time, a new array is reused and then operated. I have tried the global keyword and it does not work. It works, and adding the & reference symbol in front of the variable in use also doesn't work. What should I do?

Reply content:

Why can't the global array be used in swoole's event callback function?

Why can't the global array be used in swoole's event callback function?

As shown in the figure, the array explicitly declared in the top-level scope cannot be called in the callback function of the onmessage event. Each time, a new array is reused and then operated. I have tried the global keyword and it does not work. It works, and adding the & reference symbol in front of the variable in use also doesn't work. What should I do?

My understanding is that $server->on is called when the client sends information. In other words, the server will restart a process to handle the business logic.
So, whatever global and use you define are invalid.

This is called process isolation. In fact, swoole official documentation says it.

Why can't the global array be used in swoole's event callback function?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn