473,545 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP, cron and stdout redirection

I have a php script that queries some Oracle DB and outputs a single
line of plain text with <brat the end for each query. This is
Apache2, php4.4.8 and Oracle Instant Client 10.1.0.5 all on CentOS 4.4
32bit. Php does run as an Apache SO.

It works perfectly if I just hit the page in a web-browser (output to
browser).

It works *perfectly* from the command line (dumps the text to the file
per the redirect)
/usr/bin/php /var/www/html/dashboard/dash1.php /var/www/html/
dashboard/dash.inc

When run as cron, it updates the timestamp of the target file, but
does not write the text, nor any error.
05,15,25,35,45, 55 * * * * /usr/bin/php -q /var/www/html/dashboard/
dash1.php /var/www/html/dashboard/dash.inc

There is nothing in php error log, syslog or any other location I can
find. The entry in cron log suggests that it works perfectly. It does
not email any errors to me.

I'm very puzzled.... anyone have any idea for trouble shooting ????

philc
(this is not hosted, I control/operate the linux server)
Feb 20 '08 #1
4 3933
Phil wrote:
I have a php script that queries some Oracle DB and outputs a single
line of plain text with <brat the end for each query. This is
Apache2, php4.4.8 and Oracle Instant Client 10.1.0.5 all on CentOS 4.4
32bit. Php does run as an Apache SO.

It works perfectly if I just hit the page in a web-browser (output to
browser).

It works *perfectly* from the command line (dumps the text to the file
per the redirect)
/usr/bin/php /var/www/html/dashboard/dash1.php /var/www/html/
dashboard/dash.inc

When run as cron,
Whose cron? with what permissions?

>it updates the timestamp of the target file, but
does not write the text, nor any error.
05,15,25,35,45, 55 * * * * /usr/bin/php -q /var/www/html/dashboard/
dash1.php /var/www/html/dashboard/dash.inc

There is nothing in php error log, syslog or any other location I can
find. The entry in cron log suggests that it works perfectly. It does
not email any errors to me.

I'm very puzzled.... anyone have any idea for trouble shooting ????
Work out what effective user cron is running the script at, 'su -' to
that user, and run the exact command line from there.
Or try setting the cron entry to write to a brand new file in /tmp,
which is world writable, and see what permissions it turns up with.

and indeed whether it works...at all.
philc
(this is not hosted, I control/operate the linux server)
Feb 20 '08 #2
Greetings, Phil.
In reply to Your message dated Wednesday, February 20, 2008, 04:19:52,
I have a php script that queries some Oracle DB and outputs a single
line of plain text with <brat the end for each query. This is
Apache2, php4.4.8 and Oracle Instant Client 10.1.0.5 all on CentOS 4.4
32bit. Php does run as an Apache SO.
It works perfectly if I just hit the page in a web-browser (output to
browser).
It works *perfectly* from the command line (dumps the text to the file
per the redirect)
/usr/bin/php /var/www/html/dashboard/dash1.php /var/www/html/
dashboard/dash.inc
When run as cron, it updates the timestamp of the target file, but
does not write the text, nor any error.
05,15,25,35,45, 55 * * * * /usr/bin/php -q /var/www/html/dashboard/
dash1.php >/var/www/html/dashboard/dash.inc
There is nothing in php error log, syslog or any other location I can
find. The entry in cron log suggests that it works perfectly. It does
not email any errors to me.
I'm very puzzled.... anyone have any idea for trouble shooting ????
I think Your problem is redirection in cron job. You can't be sure what is
redirected to the file.
Redone it as follows:
<?php

ob_start();
include_once('/var/www/html/dashboard/dash1.php');
$rc = ob_get_contents ();
ob_end_clean();

$f = fopen('/var/www/html/dashboard/dash.inc', 'ab');
fwrite($f, $rc);
fclose($f);

?>
--
Sincerely Yours, AnrDaemon <an*******@free mail.ru>

Feb 20 '08 #3
On Feb 20, 8:42*am, AnrDaemon <anrdae...@free mail.ruwrote:
Greetings, Phil.
In reply to Your message dated Wednesday, February 20, 2008, 04:19:52,
I have a php script that queries some Oracle DB and outputs a single
line of plain text with <brat the end for each query. This is
Apache2, php4.4.8 and Oracle Instant Client 10.1.0.5 all on CentOS 4.4
32bit. Php does run as an Apache SO.
It works perfectly if I just hit the page in a web-browser (output to
browser).
It works *perfectly* from the command line (dumps the text to the file
per the redirect)
* */usr/bin/php /var/www/html/dashboard/dash1.php */var/www/html/
dashboard/dash.inc
When run as cron, it updates the timestamp of the target file, but
does not write the text, nor any error.
* * 05,15,25,35,45, 55 * * * * /usr/bin/php -q */var/www/html/dashboard/

dash1.php *>/var/www/html/dashboard/dash.inc
There is nothing in php error log, syslog or any other location I can
find. The entry in cron log suggests that it works perfectly. It does
not email any errors to me.
I'm very puzzled.... anyone have any idea for trouble shooting ????

I think Your problem is redirection in cron job. You can't be sure what is
redirected to the file.
Redone it as follows:

<?php

ob_start();
include_once('/var/www/html/dashboard/dash1.php');
$rc = ob_get_contents ();
ob_end_clean();

$f = fopen('/var/www/html/dashboard/dash.inc', 'ab');
fwrite($f, $rc);
fclose($f);

?>

--
Sincerely Yours, AnrDaemon <anrdae...@free mail.ru>
I might try that ... the work around that I already implemented was to
use a wget <url-O <output filein cron. Seemed kinda hack-ish, but
it did work :-)

I suspect the root cause is related to the environment, since that is
also a somewhat common problem that unix people have with other cron
scripts (shell, perl, python, etc), but not sure how to overcome it
for php in cron. Anyway, it was a rather unusual situation were I
wanted to use the same code for a live-page with DB lookups, and for
an cron-scripted output to a page for the same DB lookups.

Thanks All. Unless anyone a further brain-storm about the env for cron
php, I think this is a closed issue.
Feb 22 '08 #4
Phil wrote:
On Feb 20, 8:42 am, AnrDaemon <anrdae...@free mail.ruwrote:
>Greetings, Phil.
In reply to Your message dated Wednesday, February 20, 2008, 04:19:52,
>>I have a php script that queries some Oracle DB and outputs a single
line of plain text with <brat the end for each query. This is
Apache2, php4.4.8 and Oracle Instant Client 10.1.0.5 all on CentOS 4.4
32bit. Php does run as an Apache SO.
It works perfectly if I just hit the page in a web-browser (output to
browser).
It works *perfectly* from the command line (dumps the text to the file
per the redirect)
/usr/bin/php /var/www/html/dashboard/dash1.php /var/www/html/
dashboard/dash.inc
When run as cron, it updates the timestamp of the target file, but
does not write the text, nor any error.
05,15,25,35,45, 55 * * * * /usr/bin/php -q /var/www/html/dashboard/
dash1.php >/var/www/html/dashboard/dash.inc
>>There is nothing in php error log, syslog or any other location I can
find. The entry in cron log suggests that it works perfectly. It does
not email any errors to me.
I'm very puzzled.... anyone have any idea for trouble shooting ????
I think Your problem is redirection in cron job. You can't be sure what is
redirected to the file.
Redone it as follows:

<?php

ob_start();
include_once ('/var/www/html/dashboard/dash1.php');
$rc = ob_get_contents ();
ob_end_clean() ;

$f = fopen('/var/www/html/dashboard/dash.inc', 'ab');
fwrite($f, $rc);
fclose($f);

?>

--
Sincerely Yours, AnrDaemon <anrdae...@free mail.ru>

I might try that ... the work around that I already implemented was to
use a wget <url-O <output filein cron. Seemed kinda hack-ish, but
it did work :-)

I suspect the root cause is related to the environment, since that is
also a somewhat common problem that unix people have with other cron
scripts (shell, perl, python, etc), but not sure how to overcome it
for php in cron. Anyway, it was a rather unusual situation were I
wanted to use the same code for a live-page with DB lookups, and for
an cron-scripted output to a page for the same DB lookups.

Thanks All. Unless anyone a further brain-storm about the env for cron
php, I think this is a closed issue.

I have a sneaking suspicion it may be due to the way PHP does its
buffering. The fact that a file is CREATED means there are no perm problems.
Not sure what the actual PHP commands are, but the equivalent of an
fflush();fclose ();sync(); on stdout is something I would try..
Feb 23 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1915
by: Wes S. | last post by:
How can I redirect and tag sys.stdout values. I tried creating a class module that saved the old stdout and replaced it, but I can't seem to figure out how to do such. Here is what I got... class cStdOutRedirect : stdOld = "" def __main__(self) : stdOld = sys.stdout
0
1809
by: lickspittle | last post by:
Hi, I have Python embedded with my other code, and when my other code opens a console and redirects stdout, stdin and stderr to it, then calls PyRun_InteractiveLoop, it immediately returns with an EOF. After some debugging the reason for this appears to be that the stdin and stdout that the ReadLine function in the tokeniser include are...
10
21113
by: Michael Gaab | last post by:
If I redirect stdout by using freopen("afile", "w", stdout); and then I closed stdout using, fclose(stdout), essentially I am just closing "afile". I have to reestablish what stdout originally pointed to? thanks
2
5916
by: Thomas W. Brown | last post by:
I have setup Console redirection within my Console app (via Console.SetOut and Console.SetErrror) to route console WriteLine calls to a logfile. This works just fine with one exception... I use PInvoke to call into several unmanaged DLLs which write diagnostic information out to stdout (and possibly stderr). When I run in a "standalone"...
2
3577
by: Nadav | last post by:
Hi, Introduction: *************** I am trying to redirect stdout to a RichEdit control, this is done by initiating a StringWriter, associated it with a StringBuilder and setting the Console.Out to the String Writer, when ever the RichEdit is to be updated text from the StringBuilder is being copied. The Problem:
1
3759
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a C# application in which I start another process which produces output to stdout and stderr. In fact, that process is the uSoft VS2005 C/C++ compiler itself! I would like to capture the results of the compile and display them in a RichTextBox. The problem I'm having is that when I intentionally introduce an error in the C...
0
1815
by: Tom Gaudasinski | last post by:
Greetings, I'm trying to redirect python's stdout to another location. The reason for this is that I'm embedding python in an application. Now, originally my code was developed for Linux and that did not require redirection due to the fact that every X11 application can have an STDOUT associated with it. I then proceeded to take interest in...
4
3931
by: Aidan | last post by:
Hi, I'm having a bit of trouble with a python script I wrote, though I'm not sure if it's related directly to python, or one of the other software packages... The situation is that I'm trying to create a system backup script that creates an image of the system, filters the output though gzip, and then uploads the data (via ftp) to a...
4
2413
by: Sam | last post by:
I have a program which works great when run from the command line. But when I run it combined with something else such as: - piping it through less - cron - execl (i.e. calling it from another python program) it gives me a unicode error File "../myparser.py", line 261, in set_attributes
0
7470
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7659
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7811
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5334
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4949
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3455
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1887
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1019
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.