The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
How can i do cron job for executing my PHP file?Help me!!
Discuss How can i do cron job for executing my PHP file?Help me!! in the PHP Development forum on Dev Shed. How can i do cron job for executing my PHP file?Help me!! PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 21st, 2000, 12:36 AM
|
 |
.Net Developer
|
|
Join Date: Feb 2000
Location: London
Posts: 987
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
|
|
|
Hi,
How can i do cron job for executing my PHP script once in every day...
i want to remind the people about their birthday in reminder.php.
that would be one week before thier birthday and one day before their birthday...
can i perform this action with cron job??,
Can you tell me the syntax???.
------------------
shiju
|

February 25th, 2000, 06:22 PM
|
|
Registered User
|
|
Join Date: Aug 1999
Location: London UK
Posts: 7
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
the following is adapted from the script delivered with phpAds <http://www.phpwizard.net>. theoriginal used fetch instead of lynx which i believe is only available on FreeBSD or something...
59 23 * * * lynx -dump http://ads.ourdomain.net/mail.php3>>/var/log/messages
an alternative would be to use cgi php (which can be used at the same time as mod_php) in a script with #!/bin/php
(or whatever your path is) at the top like a perl cgi script
|

June 1st, 2000, 11:14 AM
|
|
Contributing User
|
|
Join Date: Apr 2000
Location: In nederland
Posts: 41
Time spent in forums: 40 m 2 sec
Reputation Power: 14
|
|
|
Use this perlscript it runs your php3 code..
activate the perlscript with cron.
#!/usr/bin/perl
my $url = shift;
$url = URI::URL::url($url, "http://www.??.??/cron.php3")->abs;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use MIME::Base64;
my $ua = new LWP::UserAgent;
my $request = new HTTP::Request('GET', $url);
my $res = $ua->request($request);
my $result = ($res->is_success)?$res->content:$res->error_as_HTML;
$result = $1 if $result =~ /<BODY.*?>(.*?)</BODY>/si;
$result =~ s/(<IMG.*?SRC="?)(.*?)([" >])/$1.URI::URL::url($2, $url)->abs.$3/gies;
$result =~ s/(<A.*?HREF="?)(.*?)([" >])/$1.URI::URL::url($2, $url)->abs.$3/gies;
[This message has been edited by jochum (edited June 01, 2000).]
|

June 2nd, 2000, 05:50 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
This is how we do it here at ngenuity.
Simply compile PHP as a CGI binary and move it to somewhere convenient, such as /usr/bin/.
Then make the first line of the script
#!/usr/bin/php
this tells the OS what program to process the script with, exacly like the famous
#!/usr/bin/perl
used in perl or the less famous
#!/bin/sh
used for most shell scripts.
Then in the cron tab, you can call the script directly i.e. /data/servers/www.devshed.com/scripts/script.php
This works great, especially if it is a sensitive script... you can keep it out of your web root and accessable only to your crond.
Do be sure to keep all the script within <?php ?> tags.
#!/usr/bin/php
<?
...script here...
?>
Anything print()ed, or echo()ed will be output to stdout, as will anything not in <?php ?>.
|

June 3rd, 2000, 01:09 PM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
One more question: what if I don't have access to cron on my unix system (I am using a host).
Is there a way to call lynx from a php page?
And then not wait for the process to finish?
Thanks so much
Sergio
|

June 3rd, 2000, 02:28 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
>>what if I don't have access to cron on my unix system
Can you run cron locally then? Or another system with cron access remotely to your unix system?
|

June 14th, 2000, 09:44 PM
|
|
Junior Member
|
|
Join Date: Feb 2000
Posts: 10
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
>>what if I don't have access to cron on my unix system <<
You shouldn't have access to run cron. You need to run crontab to configure cron.
|

June 15th, 2000, 05:16 PM
|
|
Contributing User
|
|
Join Date: Oct 1999
Location: SLC, UT, USA
Posts: 47

Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
Just goes to show you...learn something new everyday.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|