Page 1 of 1

Suggestions on python method needed in php

Posted: Mon Nov 06, 2006 4:13 am
by ianripping
Hi,

I have a php page which displays the entries stored in a logging database for applications that are being backed up on a server.

One thing that I am aiming to have on the php page is for it to display which process will be run next on the server.
These processes are called by the windows task scheduler.

I have written a python class which has a method for retrieving the next process that will run, out of the task scheduler.

At the moment, this method can simply return this process name / write it to a file / store it in a database.

My initial idea was to call the method every x minutes so that it updates the text file / database with the process name - which is then read by my php code - this seems a little intense.

It would make more sense for the python class to be called from my php script 'on demand', and for the returned value to be passed to the php script.

Can this be done and safely?

Thanks for any help in advance.

Here is a little diagram to help visualize what I am proposing:


Old method:
python > text file or database > php

New method
php > calls python
python > returns to php

Posted: Mon Nov 06, 2006 5:02 am
by ianripping
Ok, by googling, I have found this technique:

$command = "python_script.py"
system($command)

does this seem sustainable / acceptable?

Thanks

Posted: Mon Nov 06, 2006 5:08 am
by Chris Corbyn
ianripping wrote:Ok, by googling, I have found this technique:

$command = "python_script.py"
system($command)

does this seem sustainable / acceptable?

Thanks
Yes, I was going to suggest using shell command to acheive what you need. Seems reasonable to me.

Posted: Mon Nov 06, 2006 5:11 am
by ianripping
d11wtq wrote:
ianripping wrote:Ok, by googling, I have found this technique:

$command = "python_script.py"
system($command)

does this seem sustainable / acceptable?

Thanks
Yes, I was going to suggest using shell command to acheive what you need. Seems reasonable to me.
I am having one problem though, my python code returns the task name as a string, but when using this command, the returned value is just '0'.

$command = "python_script.py"
system($command)

I think that the 0 represents the exit code from python, do you know how I can get the returned value?

Posted: Mon Nov 06, 2006 5:12 am
by Chris Corbyn

Code: Select all

$command = "python_script.py"
$result = `$command`; //Backtick syntax to run command

echo $result;

Posted: Mon Nov 06, 2006 5:24 am
by ianripping
d11wtq wrote:

Code: Select all

$command = "python_script.py"
$result = `$command`; //Backtick syntax to run command

echo $result;
With this I get a blank page.

Posted: Mon Nov 06, 2006 7:14 am
by volka
You might be interested in http://netevil.org/node.php?nid=173&SC=1

Code: Select all

<?php
echo "<pre>\n";
foreach(win32_scheduler_enum_tasks() as $taskname) {
	print_r(win32_scheduler_get_task_info($taskname));
}
echo "\n</pre>\n";
?>

Posted: Mon Nov 06, 2006 11:05 am
by Chris Corbyn
Forgive my ignorance with python but don't you need to call "python scriptname.py" ? If not, don't you need to add "./" to the start of the command?