Home > Archive > PHP Language > February 2005 > php and stdin
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Helo guys and girls.
Before I explain my problem, this envolves a bit of *nix too, but has more
effect on php than *nix, so I hope you guys understand, I doubt asking this
question in a *nix group will result in any answers :-)
Here is my problem:
I wanna read something from stdin, and then write it to a file.
Now that part is not so hectic, the trick is, I wanna use it from syslogd.
My script that reads stdin (which I will show the code of a bit later) works
fine if I use it like this:
echo "testing123" | /usr/local/bin/php update.php
The script takes the text "testing123" and then writes it a file I specify.
If I use it in syslog.conf using the following (2) method(s), it does
nothing:
security.* |/usr/local/bin/php /path/to-the-script/update.php
security.* |exec /usr/local/bin/php /path/to-the-script/update.php
This is on a FreeBSD 5.3 machine.
What I want to do, is read the logging of ipfw, and then write it to mysql,
but before I start writing it to mysql, I first
wanna try and just write it to a normal file, from stdin, but when ever ipfw
logs something, it doesn't seem as though my script
gets excecuted as well.
Here is the code I have for update.php script:
<?php
$tmpfile = 'flogger.tmp';
$stdin = fopen('php://stdin','r');
while(!feof($stdin)) {
$mybuffer = fread($stdin, 2048);
$thetmpfile = fopen($tmpfile, 'a');
fwrite($thetmpfile, $mybuffer);
fclose($thetmpfile);
}
fclose($stdin);
?>
Now since it works from command line, I might be doing something wrong with
my syslog.conf, but I am not sure.
Would really appreaciate it if someone can point me in the right direction.
Thanks in advance.
fixx...
| |
| Colin McKinnon 2005-02-22, 8:55 am |
| fixx wrote:
> Helo guys and girls.
>
> Before I explain my problem, this envolves a bit of *nix too, but has more
> effect on php than *nix, so I hope you guys understand, I doubt asking
> this question in a *nix group will result in any answers :-)
>
> Here is my problem:
> I wanna read something from stdin, and then write it to a file.
> Now that part is not so hectic, the trick is, I wanna use it from syslogd.
>
> My script that reads stdin (which I will show the code of a bit later)
> works fine if I use it like this:
> echo "testing123" | /usr/local/bin/php update.php
> The script takes the text "testing123" and then writes it a file I
> specify.
>
> If I use it in syslog.conf using the following (2) method(s), it does
> nothing:
> security.* |/usr/local/bin/php /path/to-the-script/update.php
> security.* |exec /usr/local/bin/php /path/to-the-script/update.php
>
> This is on a FreeBSD 5.3 machine.
I'm largely guessing here, but:
1) did you remembr to restart / HUP the syslogd?
2) syslog may be splitting the argument - try enclosing it in quotes or
making update.php executable and omit the '/usr/local/bin/php' bit
3) make sure your syslogd isn't running chroot
HTH
C.
| |
|
|
"Colin McKinnon" <colin.deletethis@andthis.mms3.com> wrote in message
news:cvet55$ia0$1$8300dec7@news.demon.co.uk...
> fixx wrote:
>
more[color=darkred]
syslogd.[color=darkred]
>
> I'm largely guessing here, but:
>
> 1) did you remembr to restart / HUP the syslogd?
> 2) syslog may be splitting the argument - try enclosing it in quotes or
> making update.php executable and omit the '/usr/local/bin/php' bit
> 3) make sure your syslogd isn't running chroot
>
> HTH
>
> C.
I tried adding #!/usr/local/bin/php at the top of the file, and also making
it excecutable, but to no avail :-/
Someone must have wanted to do something similar previously, or know where I
am going wrong.
fixx
| |
| Colin McKinnon 2005-02-24, 3:56 pm |
| fixx wrote:
> Helo guys and girls.
>
> Before I explain my problem, this envolves a bit of *nix too, but has more
> effect on php than *nix, so I hope you guys understand, I doubt asking
> this question in a *nix group will result in any answers :-)
>
> Here is my problem:
> I wanna read something from stdin, and then write it to a file.
> Now that part is not so hectic, the trick is, I wanna use it from syslogd.
>
> My script that reads stdin (which I will show the code of a bit later)
> works fine if I use it like this:
> echo "testing123" | /usr/local/bin/php update.php
> The script takes the text "testing123" and then writes it a file I
> specify.
>
> If I use it in syslog.conf using the following (2) method(s), it does
> nothing:
> security.* |/usr/local/bin/php /path/to-the-script/update.php
> security.* |exec /usr/local/bin/php /path/to-the-script/update.php
>
> This is on a FreeBSD 5.3 machine.
I'm largely guessing here, but:
1) did you remembr to restart / HUP the syslogd?
2) syslog may be splitting the argument - try enclosing it in quotes or
making update.php executable and omit the '/usr/local/bin/php' bit
3) make sure your syslogd isn't running chroot
HTH
C.
|
|
|
|
|