douliao1911 2013-10-06 18:15
浏览 42

php - 为所有用户执行一次函数

I'm building an on-line multi-player board game and I have a function that creates a new board. I need to do that after every round, but i can't seem to be able to make it execute only once for all users. I call the function when the timer reaches 0, on the page where the game is situated, so it executes for every user that is on that page.

Thus, the function generates a new board as many times as there are users playing the game at that moment, but i want it to generate only one board.

So, my question is how can i make a PHP function execute only once and not as many times as there are pages open?

Edit on the system: Users play for 90 seconds then they wait 15 second while they see the round results and then the whole thing repeats again and again. And if you enter the page in the middle of the round you have the option to wait until a new round begins or enter the round right then. So i have no idea where to call the function. I tried calling it when the pause menu begins where the results are displayed, but it just executes the function for all users.It still works cause i still get one board at the end of all executions, but it's not right, especially if there will be more than hundreds of people playing, the board will be generated hundreds of time. And also, what generates the board is a c++ .exe that creates an XML on the server.I execute that exe from PHP and do some additional things also.

I have no idea where to call that function. How do i prerender the board as you said? The function still has to be on a page that some user has to access for it to execute. It's mind boggling.

And also i tried adding info in the database to see if the function has been called before, but it still happens for all users at the same time.

  • 写回答

2条回答 默认 最新

  • douhao2026 2013-10-06 18:20
    关注

    Use a database to save your board in

    When the count down reaches 0

    check if there is a board in the database, if not create new board (be aware, if it takes a long time to create a new board you could pre render a board).

    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集