need your help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
krvmanoj
Forum Newbie
Posts: 4
Joined: Tue Aug 11, 2009 6:50 am

need your help

Post by krvmanoj »

hi i am new to php. i need to run a .php file in my server everyday at a certain time.
it seems that i needed to write a bash script. i have no idea about thes things can anyone help me. tell me how to write a script in the linux server and make the .php file to run daily.
thanks in advance.
waiting eagerly for ur replay.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: need your help

Post by jayshields »

Make a cron job.
robnet
Forum Commoner
Posts: 85
Joined: Mon Aug 10, 2009 8:32 am
Location: South East, UK

Re: need your help

Post by robnet »

You don't necessarily need to write a bash script, you can schedule a php file to be executed in the same way.

the command "crontab -e" opens up an editor to allow you to schedule jobs. Make sure you use this command rather than trying to edit manually..

Here's some info in here about how to format the crontab file:
http://www.adminschoice.com/docs/crontab.htm

And your "command to be executed" would be something like "php < myphpfile.php"

So the whole line in your crontab might look like this:

Code: Select all

 
0 0 * * * php < /home/username/phpscript/myphp.php
 
This will run your script at midnight every night. - Tweak the zeros and stars to change the schedule.
krvmanoj
Forum Newbie
Posts: 4
Joined: Tue Aug 11, 2009 6:50 am

Re: need your help

Post by krvmanoj »

i am able to make that file bsc.php to run

php /home/tcemcac/public_html/bsc.php
/home/tcemcac/public_html/bsc.php
php /home/tcemcac/public_html/bsc.php


i used all the three commands. help me
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: need your help

Post by aceconcepts »

Do you know how to create a cron tab? Do you use PHPMyAdmin or something similar?
robnet
Forum Commoner
Posts: 85
Joined: Mon Aug 10, 2009 8:32 am
Location: South East, UK

Re: need your help

Post by robnet »

Try this:
php < /home/tcemcac/public_html/bsc.php

Make sure you include the "<" sign. This will direct the file into the php executable so it can run.
krvmanoj
Forum Newbie
Posts: 4
Joined: Tue Aug 11, 2009 6:50 am

Re: need your help

Post by krvmanoj »

/home/tcemcac/public_html/bsc.php: Permission denied
robnet
Forum Commoner
Posts: 85
Joined: Mon Aug 10, 2009 8:32 am
Location: South East, UK

Re: need your help

Post by robnet »

Well at least that means the cron job is running.

Can you provide some more information?

What are the permissions on bsc.php?
- From the command line type "ls -a /home/tcemcac/public_html/bsc.php" and post the output.

Which user are you when you configure the cron job?

from the command line what happens if you type "php"?
- You should get a blank prompt waiting for php input. Type "echo 'test'". If it repeats the word 'test' then php is working.

Can you paste the entire command line stuff you've just done so I can see what's going on?

Thanks
Post Reply