Synchronized block in php 7

后端 未结 4 1934
不知归路
不知归路 2021-01-20 08:20

i come from a java background where there were synchronized blocks:

The \"Synchronized\" keywords prevents concurrent access to a block of code or o

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-20 08:49

    PHP is designed to be shortlived - a PHP application is born and killed with an HTTP request.

    Every time your webserver receives an HTTP request, it will invoke a new instance of your application. This instance lives in it's own process with it's own state.

    This means that one request process cannot modify the state of another request process, but it also means that you don't have a built-in way to prevent two processes from executing the same code.

    This means you have to design your application around this constraint.

提交回复
热议问题