...

View Full Version : trigger timed actions via PHP (do x at a specific time every monday)



babelfish
05-24-2011, 04:29 PM
Hi guys

im looking to get one of our local systems to send an xml file via ftp to our website to show our current projects. the thing is i want to do this every monday morning. im unsure as to how to trigger this process. having come from a lotus notes background (shudders) one of the best things with notes was the ability to get actions to run at specific dates and times on the server

so i could tell an action to run every monday at say 8am. i have no idea how to do this via php or if its even possible?!?!

of course i could just set a a calendar entry to remind me to do it but i kind of want to know if this type of thing is even possible. plus im not so busy at the moment so making me look busy would be good :)

i think i know how to do the ftp bit but if anyone can give me an example with the ftp bit in thats cool :) (hell, im very lazy too!)

angst
05-24-2011, 04:35 PM
your best to use a CRON JOB to schedule the task.

I do something similar to upload shipping orders to my shipping servers via ftp like this;



// ftp files from file array
function FtpFileArray($FileArray){

// declare message string
$msg = "";

if(is_array($FileArray)){

// set up basic connection
$conn_id = ftp_connect(FTP_IP);

// login with username and password
$login_result = ftp_login($conn_id, FTP_USER, FTP_PASS);

// loop through array of files to be uploaded
foreach($FileArray As $FtpFile){
if(file_exists(FTP_LOCAL_PATH . $FtpFile)){

// get file type
if(Common::IsBinary(FTP_LOCAL_PATH . $FtpFile)){
$FileMode = FTP_BINARY;
} else {
$FileMode = FTP_ASCII;
}

// upload a file
if (ftp_put($conn_id, FTP_REMOTE_PATH . $FtpFile, FTP_LOCAL_PATH . $FtpFile, FTP_ASCII)) {
$msg .= "successfully uploaded $FtpFile<br />\n";
} else {
$msg .= "There was a problem while uploading " . $FtpFile . " - System Path: " . FTP_LOCAL_PATH . $FtpFile . "<br />\n";
}

} else {
$msg .= "some files were not found<br />";
}
}
// close the connection
ftp_close($conn_id);
} else {
$msg .= "invalid file array<br />";
}
return $msg;
}


just set the constants;

FTP_IP
FTP_USER
FTP_PASS
FTP_LOCAL_PATH
FTP_REMOTE_PATH

babelfish
05-24-2011, 04:40 PM
cheers mate. wth is a cron job? excuse my ignorance!

angst
05-24-2011, 04:43 PM
no prob;



The cron daemon is a long running process that executes commands at specific dates and times. To schedule one-time only tasks with cron, use at or batch. For commands that need to be executed repeatedly (e.g. hourly, daily or weekly), use crontab, which has the following options:


http://service.futurequest.net/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=30

what OS is your site running? and do you have shell or control panel access? like cpanel?

kbluhm
05-24-2011, 04:50 PM
cheers mate. wth is a cron job? excuse my ignorance!
http://www.lmgtfy.com/?q=what+is+a+cron+job

Crons can often be configured in your web host's control panel.

If you are unable to schedule a cron (not allowed, etc), there are several solutions out there that will allow a limited number of free crons, or unlimited for a fee:

http://www.setcronjob.com
http://www.webbasedcron.com
http://www.mywebcron.com
...etc.

For such services, you must have a file live on the web. Just program the file to do whatever you'd like when accessed via a simple HTTP request, as if you are visiting the file with your own browser.

When setting up cron through your host's control panel, you can theoretically access any file, whether or not it is publicly accessible, which is more secure as no one can visit the file publicly... but when using a web-based cron service, you could name your file anything you want (security through obscurity), as well as making certain $_GET parameters required, such as example.com/cron-jobs/expire-user-data-ls87Gt4FQ09Ijb27.php?allow=true

tangoforce
05-24-2011, 04:53 PM
Cron is basically the windows equivalent of the task scheduler but it will execute the script not a http request that you normally see so you'll need to check out the options as its not as simple to use.

angst
05-24-2011, 04:56 PM
actually you can execute a http request in Cron using "lynx" or "wget" to process the URL.

babelfish
05-24-2011, 05:04 PM
cheers guys! our webserver (well, in house web app box) is a little xp box sat right behind me. bizarrely performance is far better than using SBS! (we are a very small company). its running zend server community edition.

tangoforce
05-24-2011, 05:07 PM
XP imo works just as well as linux. I've hosted my website on a netbook using a 3G dongle in the past and also on a virtual XP machine too. If it can run apache, php and mysql it'll do the job ;)

angst
05-24-2011, 05:15 PM
so for windows you can just use the a scheduled task to run the job.

also, no XP does not work as well as linux, but it will do the job for some sites.

babelfish
05-24-2011, 05:23 PM
so for windows you can just use the a scheduled task to run the job.

also, no XP does not work as well as linux, but it will do the job for some sites.

all that box does is run zendserver and host our in-house management system which i wrote. so for that it works really well. oh and it streams radio one around the office.

ive never had the time to learn all the linux stuff, ive always needed windows for some of the stuff i do outsdie of work too. i learnt php creating this system and to be honest it runs and looks vastly better than pretty much all the bought in systems ive seen over the years. not bad consering i taught myself ajax and php etc while writing it :)

tangoforce
05-24-2011, 05:31 PM
If i'm honest i refer XP apache based hosting. Linux is fine but its a mythical creature you can spend years trying to tame.

babelfish
05-24-2011, 05:36 PM
If i'm honest i refer XP apache based hosting. Linux is fine but its a mythical creature you can spend years trying to tame.

:) im not a big enough star trek fan to like it :) (j/k linux guys) plus im getting too old to relearn everything again! windows is like an old annoying uncle you know very well. better the devil you know sometimes!

angst
05-24-2011, 05:37 PM
linux is not that difficult to use for most tasks. and when it comes to more advance functions and tasks. windows just won't due. and for security, windows can't compete. same with performance. not to mention licencing fee's. the list goes on. linux is better for hosting hands down.

angst
05-24-2011, 05:39 PM
absolutely, stick with what you know if it works for you. my only dispute was the comment that XP was just as good or better than linux.

tangoforce
05-24-2011, 05:59 PM
Ah, i never said better but i did say as good ;)

angst
05-24-2011, 06:05 PM
yeah and thats non-sense. it's not 'as good'. just because something runs doesn't make it as as good as something else.

a honda civic runs just fine, it'll get me back and forth from home to the office. but is it as good as a BMW? I think not.

tangoforce
05-24-2011, 06:15 PM
BMW engine using a cambelt or a honda using a chain... hmm.. define better? and how are you judging it? You might judge it by badge and speed, i judge by reliability and size of maintenance bills. Additionally I dislike BMW anyway. They once upon a time used to be a respectable car.. now every substance dealer has one. BMW drivers are also very arrogant on the road and BMW seem to encourage it which makes them worse anyway. Just because you drive a BMW doesn't give you the right to bully road users out of your way.

Seriously this happens on every forum i use. The Win vs Linux debate kicks off and its always the linux guys that start getting annoyed.

I've known lots of linux users over the years and i've dabbled with it myself on various occassions. Eventually they all come back to windows because whilst windows may be a lesser system its so much easier to do everything on it. Linux.. sure you might survive but a) there just isn't the same level of support and b) it still struggles with somethings that are so much easier on windows. I STILL after all these years cannot find a version of linux that can operate a PCI modem. With linux it's assumed you are on a LAN which is directly connected to the web. With windows it assumes nothing and lets you use whatever you want.

angst
05-24-2011, 06:44 PM
wrong.

first; there is tons of support for linux, both paid and free.

second; reliability and stability linux wins again.

also, i'm not getting annoyed, your just simply wrong in your assessment of the two systems. and i mean no offence by that.

try a google search;

http://websitehostingreport.com/

there are a million other web sites that say the same thing. and also just because windows is in your comfort zone and easier 'for you' to use. doesn't make it better or even 'as good'.

tangoforce
05-24-2011, 06:58 PM
I'm well aware of the linux stability and reliability issues. I did say i've used it in the past didn't i?

All i'm saying is that for general ease of use windows wins hands down. Unless you're one of the linux developers who knows the system inside out, work in the IT trade, have a degree in programming or are unemployed there is no real preactical way that the average joe can learn to use an entirely new OS and how to program things on it with the same ease that you can with windows.

Normal people just don't have the time for that.

angst
05-24-2011, 07:05 PM
there is no real preactical way that the average joe can learn to use an entirely new OS and how to program things on it with the same ease that you can with windows.

yes i agree with that part. and thats fair enough as I stated already, "use what you know". however that does not equate to windows being 'as good' as linux.

nuff said.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum