简体   繁体   中英

Continue script execute after PHP exec

Im using PHPs exec() function to execute a .bat file but i have a problem. The whole site hangs waiting for a response from the exec command. My .bat file contains the following... mstsc /v:192.168.1.1 the IP address is an example.

My Code

I have looked around a bit and tried adding ' > /dev/null &' to my script but adding this stops the script from executing all together. Heres my full code: (this is in my laravel controller)

public function startRemoteDesktop(Request $request)
{
    $name = $request->input('name');
    $ip_address = $request->input('ip');
    $path = public_path() . '/files/bat_files/'. $name . '.bat';
    $contents = 'mstsc /v:' . $ip_address;

    if(File::exists($path))
    {
        return 'RDP Connection Currently In Use!';
    }

    File::put($path, $contents);
    exec($path);
    File::delete($path);

    exec($path . ' > /dev/null &'); //Alternative exec command that ive tried
}

Note

Without ' > /dev/null &' added to my exec code it works fine but obviously it hangs meaning i cant do anything else with PHP until i close the RDP connection.

Question

How can i open the RDP from my exec command (or other php command) without making it pause all PHP scripts from executing?

I found that using popen($path, 'r'); allows PHP to continue script executing without waiting for the current .bat file to send a response

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