0

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!

Rahul
  • 18,271
  • 7
  • 41
  • 60
untitled8468927
  • 676
  • 4
  • 13
  • 1
    Perhaps create a [custom stream class](http://php.net/manual/en/function.stream-wrapper-register.php) that passes itself off as a zero-length stream and additionally lets you know when a read is requested? Unfortunately PHP's stream situation is rife with special cases and inconsistencies, so that could turn out to be more difficult that it sounds (or even impossible). – Jon Jan 22 '13 at 15:54

1 Answers1

1

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.

Artefacto
  • 96,375
  • 17
  • 202
  • 225