Web Hosting Buzz Reseller and Dedicated Server Hosting Forums  

Go Back   Web Hosting Buzz Reseller and Dedicated Server Hosting Forums > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 12-22-2007, 02:29 PM
JasonD's Avatar
JasonD JasonD is offline
WHB Helper
 
Join Date: Jul 2007
Posts: 143
CRON-JOB, PIPE to program, Hash-bang, Shebang (php4/5)

Through a SUPER-LONG troubleshooting session with the helpful, help department, a few things became clear about (Mail-Forward to PIPE/SCRIPT, using HASH-BANG/SHEBANG), and (Using CRON-JOBs to launch PHP SCRIPT.)

Some critical notes...
PHP 4 is the default for these methods, ("Out of box" operation)
PHP 5 requires a little more to make it operate as expected.

Please, on any AUTO-RUN style script... Use reasonable timeouts...
This stops you from CPU-ABUSE if your script runs into a dead-loop.
The default timeout for MySQL/PHP/SCRIPTS and PAGES is "UNLIMITED", by default.
<?PHP
set_time_limit(20); //Number of seconds you will allow this page/script to run
somePHPcode();
?>

==========================================
(MAIL FORWARD)====================================
==========================================

NOTE: If you use the {[Mail]-Filters}, those are treated as CRON-JOBS.

Forward to PIPE, (Found in the [Mail]-Forwarders icon of the C-Panel, not the [Mail]-Filters)
(PHP 4, PHP 5)
Your script location:
/home/yourdomain/non-www-folder/yourscript.php

What you enter in the field, "Pipe to a program"
non-www-folder/yourscript.php

(The "/home/yourdomain/" will be added by C-Panel.)

That FOLDER ("/non-www-folder/") and that FILE ("yourscript.php") must be CHMOD 0755, or 755. That is the reason you DO NOT want them to be in the (WWW) or the (Public_html) folder. This file will have to be EXECUTED, not just read and processed. These files will also NOT USE your (".htaccess") settings. You must use a HASH-BANG command, to tell them how to be processed.

The HASH-BANG: (Hash[#]-Bang[!])(/Path/to/exe)(-quiet.switch)

(PHP 4) Use this code below.
#!/usr/bin/php -q
<?PHP somePHP4Code(); ?>

(PHP 5) Use this code below.
#!/usr/local/php5/bin/php5 -q
<?PHP somePHP5Code(); ?>

NOTE: PHP 4, seems to allow the use of "Relative paths, from script location." (Suggest you still use full paths.)
EG, "include('../moreScript.php');" Relative paths work, as your DIR path is "/home/yourdomain/non-www-folder/"

NOTE: PHP 5, seems to "Forget" or "Ignore" the script location, and falls back to "SYSTEM-ROOT".
EG, "include('/home/yourdomain/moreScript.php');" Full paths are required, as your operating DIR path is "/"

NOTE: Use the -q (Quiet), if you have to OUTPUT FILE WRITES. If you use -O will send all OUTPUT to an output stream (MEMORY), and all file-writes will not occur. Using -q is similar to ">/dev/null", where as -O is more similar to ">/dev/null 2>&1", acting like a black-hole.

NOTE: Upon failure of a PIPE-EXECUTE through this MAIL-FORWARD system, the e-mail sender will be sent a notice, "MAIL DELIVERY FAILED", with the recipient seeming to be addressed to...
"To: |/usr/bin/php -q /home/yourdomain/non-www-folder/yourScript.php"
Keep that in mind, if you are using this method to be triggered by external mails. The person who sent the e-mail will get the delivery failed message, even though a COPY of the ORIGINAL real mail, was actually delivered to your e-mail address that the PIPE-EXECUTE code is setup for.

(I am looking into the MAIL-FILTERING method, which also has PIPE functionality, similar to a normal CRON-JOB setup, and may stop the "MAIL DELIVERY FAILED" issue.)

==========================================
(CRONS)==========================================
==========================================

Crons are similar, as they require the same information for EXECUTE scripts, but run as normal files. (CHMOD 0644 or 644)
(/path/to/exe)(-quiet.switch)({/optional/output/file})(/path/to/script/file)({>/optional/situation/output/files})

However, there is another, less desirable method. This uses a "Fake" http style request, using "wget".
([wget])(-quiet.switch)({/optional/output/file})([http://]path/to/script/file)({>/optional/situation/output/files})

Say that three times fast!

{No HASH-BANG required inside the PHP file, HASH-BANG is the first command of the cron.}
(PHP 4) as EXECUTE, CRON-COMMAND:
/usr/bin/php -q /home/yourdomain/non-www-folder/yourScript.php >/dev/null 2>&1

(PHP 5) as EXECUTE, CRON-COMMAND:
/usr/local/php5/bin/php5 -q /home/yourdomain/non-www-folder/yourScript.php >/dev/null 2>&1

{Using "wget", will run your PHP file, with the settings in your ".htaccess", and in your "php.ini"}
(PHP 4, PHP 5) as "wget" (Http:// or https:// request) (CHMOD Normal 0644 or 644)
wget -O http://yourdomain.com/www-located-file.php >/dev/null 2>&1
or
wget -O http://yourdomain.com/www-located-file.php?VALUE=12345 >/dev/null 2>&1

NOTE: The -q should be used only on the EXECUTE scripts, where file-writes are needed.

NOTE: -O should be used on ALL "wget" calls, unless you wish to output to an optional file. If you fail to give a file to output to, a file with a similar name to the script command will be created in your HOME folder, with every cron run.

NOTE: Do not supply an e-mail, if you want your scripts to run completely silent. If you supply an e-mail, you will/may be sent an e-mail about every cron activity. (Using the ">/dev/null" and "2>&1", should suppress e-mailing. Google it, to see what settings you might want to change.)

NOTE: Using "wget", demands that your scripts can be run by anyone in the WWW. You are broadcasting your cron-job command across the internet, not internally. These may show in LOGS, in COUNTER HITS, or other logging programs. Think security, when you use those. Also take note that http requests get dropped, blocked, lost, and time-out, and may overlap. DO NOT use "* * * * *" as your time-frame. Sending a command every minute, is similar to a DDOS-ATTACK. Not to mention, it counts towards your bandwidth tally. (60 minutes X 24 hours X 28 days = 40,320 http requests. Multiply that times one 50K file, and you have about 2GB of wasted bandwidth.)

NOTE: As you see in the second "wget", you do have the advantage of sending GET commands, with the URL. That can come in handy for weekly/monthly commands, where you might have one file, that does house-cleaning... Like deleting all those cron-job e-mails you had the crons send you. Possibly, zipping your critical html/php files. Possibly dumping your temp-files, or simply re-creating a DIR-MAP for robot crawlers.
__________________
Please realize that I am just another user of this service.
<!--// ( ISAWHIM -at- GMAIL -dot- COM ) //-->

Last edited by JasonD; 12-24-2007 at 02:35 PM.
Reply With Quote
  #2  
Old 08-11-2009, 07:10 AM
carlobee carlobee is offline
Member
 
Join Date: Jul 2009
Posts: 42
Default

indeed very long script. but definitely helpful! thanks!

Reply With Quote
  #3  
Old 10-17-2009, 04:28 PM
chinchillables chinchillables is offline
New Bee
 
Join Date: Oct 2008
Posts: 16
Default

Quote:
Originally Posted by carlobee View Post
indeed very long script but definitely helpful! thanks!
indeed it is.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump


All times are GMT. The time now is 11:07 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright WHB Networks LLC. All rights reserved.
SEO by vBSEO 3.2.0