如何使用php激活python脚本,而不是在time.sleep进行时加载页面

Using php and python I want to activate a python script, zone_on.py. My code works fine but whenever the php if statement is set my page loads and is not useable for the entire length of the python script. I want the script to be activated then the php goes back to working while the python script executes. Here is my php if statement:

$zone_on = $_GET['on'];
if (isset($zone_on)){
  $command = escapeshellcmd("python zone_on.py --zone $zone_on");
  shell_exec($command);
  // echo $output;

} 

and here is my python script named zone_on.py

import time
import argparse
import mysql.connector


number_of_zones = 7
ap = argparse.ArgumentParser()
ap.add_argument("-z", "--zone", type=str, required=True,
    help="zone number to turn on")
args = vars(ap.parse_args())



zone = [8, 7, 10, 9, 14, 15, 18, 23, 24, 25]


#time to run each zone
zone1_time = 100
zone2_time = 2
zone3_time = 2
zone4_time = 2
zone5_time = 2
zone6_time = 2


zone1  = [zone[0], zone1_time, 1]

zone2  = [zone[1], zone2_time, 2]

zone3 = [zone[2], zone3_time, 3]

zone4 = [zone[3], zone4_time, 4]

zone5 = [zone[4], zone5_time, 5]

zone6 = [zone[5], zone6_time, 6]



zone_num = args["zone"]

def openCloseValves(valve, zone_time, zone_num):
        print "Opening Zone", zone_num,"for",zone_time,"seconds"
        time.sleep(1.0)
        # GPIO.setup(valve, GPIO.OUT)
        print("Open")# GPIO.output(valve, GPIO.LOW)    # Open valve
        time.sleep(zone_time)
        print("Closed")
        # GPIO.output(valve, GPIO.HIGH)   # Close valve
        time.sleep(1.0)


def run_sprinklers():
    if zone_num == "1":
        openCloseValves(zone1[0],zone1[1], zone1[2])
    if zone_num == "2":
        openCloseValves(zone2[0],zone2[1], zone2[2])
    if zone_num == "3":
        openCloseValves(zone3[0],zone3[1], zone3[2])
    if zone_num == "4":
        openCloseValves(zone4[0],zone4[1], zone4[2])
    if zone_num == "5":
        openCloseValves(zone5[0],zone5[1], zone5[2])
    if zone_num == "6":
        openCloseValves(zone6[0],zone6[1], zone6[2])

run_sprinklers()

by default exec (shell_exec($command);) is blocking, to make it run in the background you have to deal with the output assuming you don't want it, we just throw it into the void (null)

shell_exec("$command > /dev/null 2>/dev/null &");