automatic PHP execution?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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

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.



Re: automatic PHP execution?

Peter van Schie wrote:

Quoted text here. Click to load it

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.


Re: automatic PHP execution?

Colin McKinnon wrote:
Quoted text here. Click to load it

So you check if the file exists in your script...

Quoted text here. Click to load it

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.

Quoted text here. Click to load it


Re: automatic PHP execution?

dv wrote:

Quoted text here. Click to load it

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

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

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.




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


import javax.swing.*;

import javax.swing.event.*;

import java.awt.*;

import java.awt.event.*;

import java.util.*;




* @author R. Vince


public class JavaChron extends javax.swing.JFrame {

public javax.swing.Timer timer;

public int delayseconds;

public String commander;

Properties properties;

/** Creates new form JavaChron */

public JavaChron() {

// Read properties file.




properties = new Properties();

try {

properties.load(new FileInputStream(""));

} catch (IOException ioe) {





private void initComponents() {

jPanel1 = new javax.swing.JPanel();

jButton1 = new javax.swing.JButton();

jPanel2 = new javax.swing.JPanel();

jLabel1 = new javax.swing.JLabel();

jTextField1 = new javax.swing.JTextField();

jLabel2 = new javax.swing.JLabel();

jTextField2 = new javax.swing.JTextField();

addWindowListener(new java.awt.event.WindowAdapter() {

public void windowClosing(java.awt.event.WindowEvent evt) {





jButton1.addActionListener(new java.awt.event.ActionListener() {

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





getContentPane().add(jPanel1, java.awt.BorderLayout.EAST);



jTextField1.setMinimumSize(new java.awt.Dimension(11, 40));

jTextField1.setPreferredSize(new java.awt.Dimension(200, 20));


jLabel2.setText(" Seconds");


jTextField2.setMinimumSize(new java.awt.Dimension(62, 20));

jTextField2.setPreferredSize(new java.awt.Dimension(62, 20));


getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);



private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

String s = jTextField2.getText();



// Write properties file.

properties.setProperty("delayseconds", jTextField2.getText());

properties.setProperty("commander", jTextField1.getText());

try { FileOutputStream(""), null);

} catch (IOException ioe2) {





timer = new javax.swing.Timer(1000*delayseconds, new
java.awt.event.ActionListener() {

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

try {

Process process = Runtime.getRuntime().exec(commander);


} catch (Throwable ex) {








/** Exit the Application */

private void exitForm(java.awt.event.WindowEvent evt) {





* @param args the command line arguments


public static void main(String args[]) {

new JavaChron().show();


// Variables declaration

private javax.swing.JButton jButton1;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JPanel jPanel1;

private javax.swing.JPanel jPanel2;

private javax.swing.JTextField jTextField1;

private javax.swing.JTextField jTextField2;


Re: automatic PHP execution?

dv wrote:
Quoted text here. Click to load it

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.


Site Timeline