Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP exec command

Status
Not open for further replies.

rtgadgetboy

Programmer
Apr 30, 2003
6
US
Hi all,

I am writing a PHP page that runs an external script. The script writes some text to a .txt file. When I run the script on the command line, it executes fine and the .txt file is updated. When I run the script from my PHP page, the script deletes what was already in the .txt file but does not update it.

I am running the script using the exec command in PHP->

exec("CLIPS.EXE -f p.clp");

clips is the program that runs the script-> p.clp

Any help much appreaciated.

Gadgetboy
 
Nope, the php page displays fine without any errors. I havnt yet enabled input/output watching on the script so I will give that a go.
 
And we can all assume that CLIPS.EXE -f p.clp works perfectly fine when run from the command line?

Another thing to consider is that the command will not be executed by the same user as if you enter it on the command line (I'll assume windows with the .exe), depending on your web server it will run as SYSTEM or some other user. This can be changed if it's a problem.

-Rob
 
Hi skiflyer,

clips.exe -f p.clp does indeed work fine from the command line. I am interested in the fact that the web server would be running the program as SYSTEM and not under my windows user. You mention it can be changed- how would this be done?

cheers,
gadgetboy
 
Well, what's your setup? Apache? What version of windows?

I'll tell you real quickly for Apache 2 in Windows 2k because that's what's right in front of me.

Get to your services however you best like. I prefer right clicking my computer and choosing manage.

Then select the Apache2 service. Right click and choose Properties. Click the log on tab and select the radio button for Log on as: labelled This account: and fill out the text fields. Then restart apache.

-Rob
 
My setup:

WIN XP PRO SP1
Apache 1.3.27

I added my account to the log-on properties of apache.
The script now writes to the file, but for some reason seems to stop half-way. I really have no idea why this would happen as the file should be written all in one go.

Again any ideas are much appreciated,
gadgetboy
 
Which browser? I ask out of curiosity because I had similar problems (but different, was a feedback hang rather than a process hang) with Mozilla and Opera, but IE ran it fine.

I guess Mozilla and Opera weren't in the mood to wait for PHP to finish up it's shell.

Just as a note... be careful adding your account if this machine faces the web, in that case you should create a very limited account which has access to only what it needs.

also, how long does clip.exe take to run? I'm fairly certain php.ini has some timeouts and such for how long exec commands can take, but right now I don't have that available to me.

-Rob
 
Running IE 6.

clips.exe only takes a couple of seconds to run, so i wouldnt have thought there would be a time issue.

The timeout for my php.ini is 30 secs and the memory limit is 8MB. I took a screen shot when i loaded the page that runs the script and there are a number of processes that appear. There is a SERVICES.EXE which needs 10MB of memory.
I have tried allocating more memory to the scripts (20MB) but this did not have any effect.

cheers,
gadgetboy
 
Just out of curiosity:

What makes it necessary to run an external script to write some text to a .txt file? The task could be entirely accomplished in PHP.
 
I am testing some other ways to create data that we need as part of our business. This script is one of these tests but needs to be run from a PHP environment.

cheers,
gadgetboy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top