how to make a php crontab silent
Solution 1
use -q
it means "quiet" and thus doesn't generate output
* * * * * php -q /home/public_html/folder/file.php
also, ask yourself why you want to run it every minute, that's a little excessive.
Solution 2
2>&1
redirects the everything written to stderr to stdout
>/dev/null
redirects stdout to /dev/null
cron will always email you anything sent to stdout or stderr unless redirected elsewhere. Ideally, your PHP script should be rewritten to accept a --quiet flag that doesn't write a whole bunch of useless crap out to stdout, which you could then use in your cron job.
The lazy man's option is to put a wrapper script around your cron job that will stop it from emailing you unless your command exits non-zero.
Related videos on Youtube
roshkattu
Updated on September 17, 2022Comments
-
roshkattu almost 2 years
I am using the YoutubeDL library in a project. My environment is based on WINDOWS with XAMPP as the webserver boundle (apache,php,mysql,etc). I am using the youtube-dl.exe file to download the video and then use ffmpeg.exe to convert the video to an MP3 audio file.
At the moment, I have an issue related to programming: I want to show live a progressbar while the video is downloaded with the youtube-dl.exe file. This exe creates a log file, that is updated while the video is downloaded. So my approach on this was to create a PHP file, that opens, parses the log file and get's the progress percent, and sends it as a json encoded value to an AJAX function that is called every 100MS. Indeed, if the video is too large, there will be a very high ammount of data while polling the PHP file to get the progress state. And sometimes, the browser either crashes or freezes because of this ajax polling.
My question is: is there any better approach to do this with PHP/AJAX? Rathar than poll the file every 100MS, or 50MS?
-
Musikdoktor over 4 yearsRosh can you please share how you managed to print on a file the download progress? im on windows and xampp too but i tried popen ytdl and then write a txt but for some reason i cant get anything inside the file.. Can you please share your approach?
-
-
rodjek over 13 yearsYou're assuming that errors are being printed to stderr rather than stdout. This is not a safe assumption.
-
Brooke. over 13 yearsI see. I also see that curl has --silient but can I curl an php script?
-
Istvan over 13 years@BandonRandon, you can curl URLs like http/https if this was your question.
-
Brooke. over 13 yearsIt's a crontab that checks the status of buses in real time. The file is checking to see how many minutes the bus is away and if it's close alerts the user.
-
Brooke. over 13 years@l1x yes that was my question. That would make it run just like loading it in the browser correct?
-
Istvan over 13 years@BandonRandon yes, like yourdoma.in/folder/file.php
-
Brooke. over 13 yearsAlso,
-q
did the trick. -
Brooke. over 13 yearsOkay, so that's another route to go. The accept answer seemed to be a simple solution.
-
Tom O'Connor over 13 yearsIf it needs to run once a minute, what's the problem with that? Surely the developer knows why it needs to run so frequently...
-
mhmpl over 13 years@Tom generally cron may not be the right solution for things that need to run that often. But that's an opinion, and one that we enforce at work.
-
Brooke. about 13 years@xenoterracide what are some other options to check a database and sent out alerts on a realtime basis?
-
mhmpl about 13 years@bandnon 1 minute intervals aren't realtime anyways... but long running scripts that poll will do it, event driven programming might be good, when an alert is generated, send it.