473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

automatic PHP execution?

dv
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
?

Mar 27 '06 #1
6 1976
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.

--
http://www.phpforums.nl

Mar 27 '06 #2
dv wrote:
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
?


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
Mar 27 '06 #3
Ike
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.event.*;

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import java.io.*;

/**

*

* @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.

initComponents();

show();

pack();

properties = new Properties();

try {

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

} catch (IOException ioe) {

}

jTextField2.setText(properties.getProperty("delays econds"));

jTextField1.setText(properties.getProperty("comman der"));

}

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) {

exitForm(evt);

}

});

jButton1.setText("Go");

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

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

jButton1ActionPerformed(evt);

}

});

jPanel1.add(jButton1);

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

jLabel1.setText("Command");

jPanel2.add(jLabel1);

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

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

jPanel2.add(jTextField1);

jLabel2.setText(" Seconds");

jPanel2.add(jLabel2);

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

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

jPanel2.add(jTextField2);

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

pack();

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

String s = jTextField2.getText();

delayseconds=Integer.parseInt(s);

commander=jTextField1.getText();

// Write properties file.

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

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

try {

properties.store(new FileOutputStream("JavaChron.properties"), null);

} catch (IOException ioe2) {

}

jButton1.setEnabled(false);

jTextField2.setEnabled(false);

jTextField1.setEnabled(false);

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);

//process.waitFor();

} catch (Throwable ex) {

ex.printStackTrace();

}

}

});

timer.setInitialDelay(1000*delayseconds);

timer.start();

}

/** Exit the Application */

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

timer.stop();

System.exit(0);

}
/**

* @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;
}

Mar 28 '06 #4
Peter van Schie wrote:
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.


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.

Mar 28 '06 #5
dv wrote:
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
?


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:

http://www.arches.uga.edu/~pkeck/ssh/

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
Mar 28 '06 #6
Colin McKinnon wrote:
Peter van Schie wrote:
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.

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


So you check if the file exists in your script...
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.
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.
You could redirect the logfile of the FTP server to a program which could
trigger appropriate responses.


Peter.
--
http://www.phpforums.nl

Mar 28 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bruce W...1 | last post by:
Does PHP do automatic garbage collection, or should you explicitly destroy things. I found this statement mysql_free_result($result); This makes me wonder. Thanks for your help.
7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
1
by: Melissa Meyer via SQLMonster.com | last post by:
How do you set a stored proceedure for automatic execution? -- Message posted via http://www.sqlmonster.com
6
by: Gert van der Kooij | last post by:
Hi, It's no problem to define the automatic maintenance using the wizard but I want to use commands to automate automation. I captured the SQL statements when activating the maintenance but that...
1
by: Michel Esber | last post by:
Hello, Linux RedHat AS4 running DB2 V8 FP11. I have followed the docs at http://tinyurl.com/qckrn and enabled automatic statistics collection. It has been 2 days since I updated my DB cfg and...
58
by: Jorge Peixoto de Morais Neto | last post by:
I was reading the code of FFmpeg and it seems that they use malloc just too much. The problems and dangers of malloc are widely known. Malloc also has some overhead (although I don't know what is...
3
by: myjish18 | last post by:
Hello, We have a DB2 UDB database v8.2.7 (db2 v8.2 fixpak 14) on AIX 5.3 which has Automatic Storage (AS) enabled. We want to disable automatic storage on entire database and/or disable...
5
by: mike.m.schmidt | last post by:
Hello, I've been trying to optimize a piece of code that executes in 6 milliseconds. From what I have read, dynamically managing memory with new/malloc and delete/free is less efficient than...
5
by: trss | last post by:
Has anyone experienced automatic memoization by any C++ compiler before? The program coded as a solution for the problem based on the famous 3n +1 problem, both of which are given below, is...
25
by: sidd | last post by:
In the following code: int i = 5; ---it goes to .data segment int j; ---it goes to bss segment int main() { int c; int i = 5; ---stack
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.