Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Question trigger timed actions via PHP (do x at a specific time every monday)

    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!)
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    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;

    PHP Code:
        // 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_idFTP_USERFTP_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_idFTP_REMOTE_PATH $FtpFileFTP_LOCAL_PATH $FtpFileFTP_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

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    cheers mate. wth is a cron job? excuse my ignorance!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #4
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    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...kbarticleid=30

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

  • #5
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Quote Originally Posted by babelfish View Post
    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
    Last edited by kbluhm; 05-24-2011 at 03:57 PM.

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #7
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    actually you can execute a http request in Cron using "lynx" or "wget" to process the URL.

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    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.
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #9
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    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
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #10
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    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.

  • #11
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by angst View Post
    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
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #12
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #13
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    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!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #14
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    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.

  • #15
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    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.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •