简体   繁体   中英

How to delay exec command in php

I know this kind of question has been asked many times, but I haven't found a suitable answer yet. Here it is:

I have a site - apache/php/mysql on debian. I've managed to allow www-data to execute iptables commands. Now I need to find out if I can delay such a command without making the user/browser wait.

What's the point? - When a user authenticates php will get his public IP address and will open a port in the firewall. I want this port to be open for (let's say) 2 minutes (enough time to establish a VPN connection), and then I want the port to be closed.

So, basically, I want PHP to exec a command, and then, after 2 minutes, to execute another command - all this without making the browser wait for those two minutes.

From the user's perspective: John authenticates at test.com and immediately closes his browser and starts his vpn connection. If he closes the VPN connection after the 2 minute period, he has to logon again.

Is this possible?

Thank you.

使用at

shell_exec('echo "iptables --something 1.2.3.4" | at now + 2 minutes');

php是否有一个bash脚本,可在您睡眠2分钟后为您运行iptables命令?

作为单独的脚本运行它,不要等待它完成,

exec("/usr/bin/php script.php &");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM