0

I have built a small car robot using Raspberry Pi. The control for the robot is accessed via an apache webserver hosted on the Pi, which uses PHP to drive the motors based on user input. I plan to open this robot to the internet to allow anyone to control it, but my question is: Is there a way to control the amount of users connected to the webserver, as I would like only one person at a time to be able to control the bot?

4

1 回答 1

0

将机器人的功能放在一页中。当有人访问该页面时,会创建一个临时文件,例如 temp.lock。

访问页面时检查 temp.lock 文件的创建,如果 temp.lock 文件存在,则拒绝访问该页面。

用户关闭页面或发生超时后,删除 temp.lock 文件。

创建临时文件:

$temp = tmpfile();
fwrite($temp, "writing to tempfile");
fseek($temp, 0);
echo fread($temp, 1024);
fclose($temp); // this removes the file

PHP:tmpfile
Daniweb.com

于 2018-01-25T17:55:48.330 回答