Question

I know it's possible to log the output of a job execution to a FILE, but what I want is to actually call another php script passing that log data so I can process it with php:

<?php
$cronLog = file_get_contents('php://input'); // get the cronjob log
save_to_database($cronLog);

And in crontab something like this:

*/1 * * * * /usr/bin/php /path/to/CRON.php >> /usr/bin/php /path/to/my/php/save_to_database.php

I'm no unix expert, is this even possible?

Was it helpful?

Solution

What you're missing is the | pipe operator. Currently what you're doing is using >> which will append to a file, and add junk to the right-side script.

What you really want to do is something like:

* * * * * php -q /path/to/first.php | php -q /path/to/read_stdin.php

This pipes the stdout of the left-side php script to the right hand side php script, which you can read with fopen('php://stdin', 'r'); for example.

Pipes are really handy and wikipedia knows more about them, if you want to learn some more.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top