To my PHPeoples,
This is sort of a weird PHPuzzle, but I'm wondering if it's PHPossible.
The end goal is the equivalent functionality of
mysql mydb < file.sql
But with an API like this
./restore < file.sql
Where restore
is a PHP script like this
#!/usr/bin/env php
$cmd = "msyql mydb";
passthru($cmd, $status);
However, I want to pass STDIN to the passthru
command.
The clear benefit here is that I can put restore
somewhere in a pipeline and everything works peachy. Here's an example
# would be pretty awesome!
ssh $remote "msyqldump $config mydb | gzip" | gzip -dc | ./restore
Anyway, I doubt it's possible using passthru
, but perhaps with proc_open
in some way?
As a last case resort, in the event of an unsolvable PHPredicament, I would do something like this
./restore file.sql
With script like this
#!/usr/bin/env php
$cmd = sprintf("mysql mydb < %s", $argv[1]);
passthru($cmd, $status);
PHPwnd
./restore
Example use
What! PHProfound!
Turns out
passthru
already does this! PHenomenalP!Check it out, PHPals:
gzip.php
How PHProgressivist!
Output