Suggestions on python method needed in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ianripping
Forum Newbie
Posts: 17
Joined: Thu Feb 05, 2004 3:20 am
Location: Leeds, UK

Suggestions on python method needed in php

Post 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
ianripping
Forum Newbie
Posts: 17
Joined: Thu Feb 05, 2004 3:20 am
Location: Leeds, UK

Post by ianripping »

Ok, by googling, I have found this technique:

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

does this seem sustainable / acceptable?

Thanks
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
ianripping
Forum Newbie
Posts: 17
Joined: Thu Feb 05, 2004 3:20 am
Location: Leeds, UK

Post 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?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

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

echo $result;
ianripping
Forum Newbie
Posts: 17
Joined: Thu Feb 05, 2004 3:20 am
Location: Leeds, UK

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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";
?>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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?
Post Reply