untitled8468927
untitled8468927

Reputation: 686

PHP proc_open - Bail out if process requires input

So - I'm using proc_open() to execute programs such as ssh, rsync, scp etc. to perform backup tasks.

However, in some cases, these processes could become interactive and require input, for example when public key authentication fails for SSH, and it asks for a password. This is a major problem because it's out of the question to let a backup job hang, and worse yet, not generate an error.

How do I get completely rid of interactivity in the processes I'm running? If the process suddenly requires input, I want to bail out and generate an error immediately. A generic time-out is not a solution, because the backup processes could take a very long time in normal operation. I'd really need a generic solution to this problem.

Thanks!

Upvotes: 0

Views: 304

Answers (1)

Artefacto
Artefacto

Reputation: 97835

Just pass an empty file as stdin:

 $r = proc_open('cat', [fopen('/dev/null', 'rb')], $p);
 proc_close($r)

This scripts ends in a few miliseconds.

Upvotes: 1

Related Questions