WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Newbie Notes #8 - A cron trick
Categories : PHP, CURL, Beginner Guides Click here to Update Your Picture
Simon Booth
Date : Apr 23rd 2004
Grade : 2 of 5 (graded 7 times)
Viewed : 9188
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Simon Booth
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

NewbieNotes is a little series of tips for people who are new to PHP to give them a few handy tips that the more experienced of us use often

It's often desirable to perform certain tasks once a day, usually in the early hours of the morning. Such tasks are usually handled by PERL scripts, but PHP is equally up to the task.

All you need to do is create a web page that performs whatever task you wish to perform and somehow automate it being loaded at the given time

There is a small trick involved in running a PHP script in the middle of the night when nobody is around to start it going. The best thing about this method is that you don't need to have the command line version of PHP on the server you're using - frequently an omission with hosted sites.

As long as you can either install or already have access to a program called CURL and can set up a cron job everything else is possible.

CURL is an excellent little program, available from http://curl.haxx.se, that grabs web pages off the net, optionally saving them to a file.

Using CURL you can run your script using a command line along the lines of...

curl http://www.myserver.dom/myscript.pghp > output.htm

If you insert this command, with your script as the page loaded into your cron file it's a simple matter to run daily/nightly routines written entirely in PHP



Using PHP im HTML image tags
Categories : PHP, HTML and PHP, Graphics, Beginner Guides
Newbie Notes #7 - Ridiculous regex
Categories : PHP, Beginner Guides, Regexps
Real simple example of removing HTML tags from text then changing \n (new line) to <br>. Could be used in a forum for instance.
Categories : HTML, PHP, HTML and PHP, Beginner Guides
Form Validation Using PHP to highlight non valid fields
Categories : PHP, Form Processing, Data Validation, Beginner Guides
Link Submition - Allow your visitors to submit links to the site.
Categories : PHP, Arrays, Filesystem, Beginner Guides
Simple Cookie example
Categories : PHP, Beginner Guides, Cookies
a PHP Function to Get only the filename (remove the extension) using regular expressions.
Categories : PHP, Regexps, Beginner Guides
for each record, do this to the first record, and do that to any subsequent record
Categories : PHP, Databases, MySQL, Beginner Guides
Specify your connection settings and create a link to a MySQL database.
Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides
Upload Via FTP - an alternative to move_uploaded_file
Categories : PHP, FTP, Beginner Guides
Newbie Notes #5 - To double quote, or single quote, that is the question
Categories : PHP, Beginner Guides, Variables
Cut your MySQL Connections to 1 line of code
Categories : PHP, Beginner Guides, Databases, MySQL
Basic Authentication with sessions
Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions
Change the background color of a website daily dynamically using the php date function to get the current day of the week and depending on that day, set the background color for the web page.
Categories : PHP, Date Time, Beginner Guides, Web Design
PHP Function for Random Digits
Categories : PHP, Beginner Guides
 Valics Lehel wrote : 1084
An another solution is to programming in that way, that once a day, your 1st visitor, start a "fake cron" script. So teoretically the cron will be the first visitor.
We use this in sites where we don`t have access to CRON table. Is not very nice, because on large sites, that specific user can wait to long for page, but we did not find an another way.
Also cURL is not installed on all servers. So what you do if is not installed?

Also for people who do "crons" like this, http://www.mydomain.com/cron_script.php and have a possibilities to call from shell, better use 

#!/usr/bin/php -q
&lt;?php

if ($_SERVER["HTTP_ACCEPT"] != `` && $_SERVER["HTTP_ACCEPT_LANGUAGE"] != ``) {
    die(`This script can only be run via a shel terminal, not via your browser.`);
    exit();
}

script continue here.
 
 Simon Booth wrote :1085
The point I was making wathe usefullness of curl

You can always instll CURL, even on a hosted box. Then ouy can run a zscript to automate just about anything you like

If you fail to understand this - fine - I`m just tryig to help people out