automatic PHP execution?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dv

    #1

    automatic PHP execution?

    Hi,

    I have the following question,
    I have an application which transfers a csv file (via FTP) to the server
    then on the server I have a PHP script which put the content of the CSV into
    a mysql
    The question is now how can I start without manual interaction this PHP file
    ?



  • Peter van Schie

    #2
    Re: automatic PHP execution?

    On Windows you can use Task Scheduler on Linux and UNIX you can use a
    cronjob, check out: execute the command crontab -e to add the cronjob
    and check out man crontab.

    HTH.
    Peter.

    --


    Comment

    • Disco Octopus

      #3
      Re: automatic PHP execution?

      dv wrote:
      [color=blue]
      > Hi,
      >
      > I have the following question,
      > I have an application which transfers a csv file (via FTP) to the server
      > then on the server I have a PHP script which put the content of the CSV into
      > a mysql
      > The question is now how can I start without manual interaction this PHP file
      > ?[/color]

      can you use 'cron' to perform what you need? Maybe you can look into some
      kind of directory poleing software? not sure much about these, but perhaps
      you can look into setting a cron job to do what you are after?

      --
      if it itches, it will be scratched

      Comment

      • Ike

        #4
        Re: automatic PHP execution?

        here is a little java applicaiton I wrote -- if you need the compiled files
        I can send them - email me rvince99 at hotmail dot com. Anyhow, you merely
        specify how many seconds you want to wait before re-invoking something. For
        instance, if I want to execute test.php and it is in c:\x, my command would
        be:

        c:\php\php.exe c:\x\test.php

        I wrote this so that php scripts, java pplications, etc., can be invoked
        every X seconds without regard to platform.

        /*

        * JavaChron.java

        *

        * Created on March 17, 2006, 1:52 PM

        */

        import javax.swing.*;

        import javax.swing.eve nt.*;

        import java.awt.*;

        import java.awt.event. *;

        import java.util.*;

        import java.io.*;

        /**

        *

        * @author R. Vince

        */

        public class JavaChron extends javax.swing.JFr ame {

        public javax.swing.Tim er timer;

        public int delayseconds;

        public String commander;

        Properties properties;

        /** Creates new form JavaChron */

        public JavaChron() {

        // Read properties file.

        initComponents( );

        show();

        pack();

        properties = new Properties();

        try {

        properties.load (new FileInputStream ("JavaChron.pro perties"));

        } catch (IOException ioe) {

        }

        jTextField2.set Text(properties .getProperty("d elayseconds"));

        jTextField1.set Text(properties .getProperty("c ommander"));

        }



        private void initComponents( ) {

        jPanel1 = new javax.swing.JPa nel();

        jButton1 = new javax.swing.JBu tton();

        jPanel2 = new javax.swing.JPa nel();

        jLabel1 = new javax.swing.JLa bel();

        jTextField1 = new javax.swing.JTe xtField();

        jLabel2 = new javax.swing.JLa bel();

        jTextField2 = new javax.swing.JTe xtField();

        addWindowListen er(new java.awt.event. WindowAdapter() {

        public void windowClosing(j ava.awt.event.W indowEvent evt) {

        exitForm(evt);

        }

        });

        jButton1.setTex t("Go");

        jButton1.addAct ionListener(new java.awt.event. ActionListener( ) {

        public void actionPerformed (java.awt.event .ActionEvent evt) {

        jButton1ActionP erformed(evt);

        }

        });

        jPanel1.add(jBu tton1);

        getContentPane( ).add(jPanel1, java.awt.Border Layout.EAST);

        jLabel1.setText ("Command");

        jPanel2.add(jLa bel1);

        jTextField1.set MinimumSize(new java.awt.Dimens ion(11, 40));

        jTextField1.set PreferredSize(n ew java.awt.Dimens ion(200, 20));

        jPanel2.add(jTe xtField1);

        jLabel2.setText (" Seconds");

        jPanel2.add(jLa bel2);

        jTextField2.set MinimumSize(new java.awt.Dimens ion(62, 20));

        jTextField2.set PreferredSize(n ew java.awt.Dimens ion(62, 20));

        jPanel2.add(jTe xtField2);

        getContentPane( ).add(jPanel2, java.awt.Border Layout.CENTER);

        pack();

        }


        private void jButton1ActionP erformed(java.a wt.event.Action Event evt) {

        String s = jTextField2.get Text();

        delayseconds=In teger.parseInt( s);

        commander=jText Field1.getText( );

        // Write properties file.

        properties.setP roperty("delays econds", jTextField2.get Text());

        properties.setP roperty("comman der", jTextField1.get Text());

        try {

        properties.stor e(new FileOutputStrea m("JavaChron.pr operties"), null);

        } catch (IOException ioe2) {

        }

        jButton1.setEna bled(false);

        jTextField2.set Enabled(false);

        jTextField1.set Enabled(false);

        timer = new javax.swing.Tim er(1000*delayse conds, new
        java.awt.event. ActionListener( ) {

        public void actionPerformed (java.awt.event .ActionEvent e) {

        try {

        Process process = Runtime.getRunt ime().exec(comm ander);

        //process.waitFor ();

        } catch (Throwable ex) {

        ex.printStackTr ace();

        }

        }

        });

        timer.setInitia lDelay(1000*del ayseconds);

        timer.start();

        }

        /** Exit the Application */

        private void exitForm(java.a wt.event.Window Event evt) {

        timer.stop();

        System.exit(0);

        }


        /**

        * @param args the command line arguments

        */

        public static void main(String args[]) {

        new JavaChron().sho w();




        }



        // Variables declaration

        private javax.swing.JBu tton jButton1;

        private javax.swing.JLa bel jLabel1;

        private javax.swing.JLa bel jLabel2;

        private javax.swing.JPa nel jPanel1;

        private javax.swing.JPa nel jPanel2;

        private javax.swing.JTe xtField jTextField1;

        private javax.swing.JTe xtField jTextField2;


        }



        Comment

        • Colin McKinnon

          #5
          Re: automatic PHP execution?

          Peter van Schie wrote:
          [color=blue]
          > On Windows you can use Task Scheduler on Linux and UNIX you can use a
          > cronjob, check out: execute the command crontab -e to add the cronjob
          > and check out man crontab.
          >[/color]

          That's a crappy way to solve the problem. Most times the program runs, the
          file isn't going to be there.

          Really the most elegant solution would be to get the FTP server to send a
          notification or launch the script itself - but that's not very likely.

          You could redirect the logfile of the FTP server to a program which could
          trigger appropriate responses.

          Dazuko would be a cool way to solve the problem. Or maybe fam.

          Just a few thots.

          C.

          Comment

          • Michael Trausch

            #6
            Re: automatic PHP execution?

            dv wrote:[color=blue]
            > Hi,
            >
            > I have the following question,
            > I have an application which transfers a csv file (via FTP) to the server
            > then on the server I have a PHP script which put the content of the CSV into
            > a mysql
            > The question is now how can I start without manual interaction this PHP file
            > ?
            >[/color]

            If the application runs on UNIX, the best way to do this would be
            probably be to have the thing start an SSH session and execute the PHP
            script directly; however you have to have SSH access to the host on
            which PHP is running to do so.

            The way to do it would be to create an SSH key for a single purpose. A
            good tutorial on that is on the web at:



            If that won't work for you, then you should just put the PHP script
            somewhere in the web namespace and have your application call it
            directly. You can do that by opening a connection to port 80, and
            sending an appropriate GET string to run the script. In addition, you
            can have the script throw output, but you would need to parse the HTTP
            headers that are returned before the script's output.

            HTH,
            Mike

            Comment

            • Peter van Schie

              #7
              Re: automatic PHP execution?

              Colin McKinnon wrote:[color=blue]
              > Peter van Schie wrote:
              >[color=green]
              > > On Windows you can use Task Scheduler on Linux and UNIX you can use a
              > > cronjob, check out: execute the command crontab -e to add the cronjob
              > > and check out man crontab.
              > >[/color]
              >
              > That's a crappy way to solve the problem. Most times the program runs, the
              > file isn't going to be there.[/color]

              So you check if the file exists in your script...
              [color=blue]
              > Really the most elegant solution would be to get the FTP server to send a
              > notification or launch the script itself - but that's not very likely.[/color]

              Speaking of crappy ways....
              Why not just do the most logical thing and use the appropriate services
              to solve a problem?
              You cannot tell me you'd really modify the code of your ftp server
              software to solve a simple problem like this.
              [color=blue]
              > You could redirect the logfile of the FTP server to a program which could
              > trigger appropriate responses.[/color]

              Peter.
              --


              Comment

              Working...