exec php

exec php

am 21.12.2007 14:01:05 von warth33

Hello

I have a php site. Some page needs to call an external program. The
programs are home made c# applications.

It uses to work without problem. For a while. Maybe it work for some
hour. Or for a day. Or even for a week.

At a certain point, when a php script calls the exe file, the
application freezes. The following happens:

$return_value = exec('path_to_exe_file');
echo $return_value;
?>

Well, the exec is executed (I can see that, the exe fil does what it
has to do). But it doesnt return to the php-script. The php-script
waits infinitely that the app will return, but it will not return. At
a certain point the time execution exeedes.

If I go to the command line and execute an exe file (the same one that
exec calls), then it works without problem, and returns immediatly.
But from the exec call it doesnt return.

How do I solve this? Well, I restart the server. And hen everything
works again. Which means that the script can use exec again without
waiting infinitely.

When the problems begin (when the exec begins to fail) the server can
still work without problem. All the scripts run. The only scripts that
dont run are those that have the exec call inside.

error.log doesnt says anything about this.

Im running apache 2.X on windows server 2003. PHP version is 5.x.

I have put log function before and after every single call to exec. I
analyzed it, but I can not understand why the exec fails. It only
stops to get back the return value from the c# app. The c# app can
also be a simple one with only a console.write (something like echo).
But when exec has hanged up neither that will work.

Someone can see the problem?

Re: exec php

am 21.12.2007 18:56:06 von Betikci Boris

On Dec 21, 3:01=A0pm, wart...@hotmail.com wrote:
> Hello
>
> I have a php site. Some page needs to call an external program. The
> programs are home made c# applications.
>
> It uses to =A0work without problem. For a while. Maybe it work for some
> hour. Or for a day. Or even for a week.
>
> At a certain point, when a php script calls the exe file, the
> application freezes. The following happens:
>
> > =A0 =A0$return_value =3D exec('path_to_exe_file');
> =A0 =A0echo $return_value;
> ?>
>
> Well, the exec is executed (I can see that, the exe fil does what it
> has to do). But it doesnt return to the php-script. The php-script
> waits infinitely that the app will return, but it will not return. At
> a certain point the time execution exeedes.
>
> If I go to the command line and execute an exe file (the same one that
> exec calls), then it works without problem, and returns immediatly.
> But from the exec call it doesnt return.
>
> How do I solve this? Well, I restart the server. And hen everything
> works again. Which means that the script can use exec again without
> waiting infinitely.
>
> When the problems begin (when the exec begins to fail) the server can
> still work without problem. All the scripts run. The only scripts that
> dont run are those that have the exec call inside.
>
> error.log doesnt says anything about this.
>
> Im running apache 2.X on windows server 2003. PHP version is 5.x.
>
> I have put log function before and after every single call to exec. I
> analyzed it, but I can not understand why the exec fails. It only
> stops to get back the return value from the c# app. The c# app can
> also be a simple one with only a console.write (something like echo).
> But when exec has hanged up neither that will work.
>
> Someone can see the problem?

Bad combination! Apache server on Windows 2003 server. Thy combination
really diminishes the performance and may cause those freezes

You should switch to GNU/Linux-Apache/php or Windows2003/IIS/Asp.NET

Re: exec php

am 21.12.2007 19:54:47 von unknown

Post removed (X-No-Archive: yes)

Re: exec php

am 21.12.2007 21:28:00 von warth33

> Since the exec() function isn't expecting anything back, it might be worth
> trying either "shell_exec()" or "system()" since those would get back some
> output from the program being accessed.
>
> Tom
The thing is that the php function is expecting something back. Thus
getting the result of the exec command is needed by the php script.
About the bad combination: The site is running windows media server,
so I cannot go to linux. And I cannot recreate a whole site, a big
one, in asp.net!

Re: exec php

am 22.12.2007 18:09:14 von geekprogrammer.ed

On Dec 21, 8:01 am, wart...@hotmail.com wrote:
> Hello
>
> I have a php site. Some page needs to call an external program. The
> programs are home made c# applications.
>
> It uses to work without problem. For a while. Maybe it work for some
> hour. Or for a day. Or even for a week.
>
> At a certain point, when a php script calls the exe file, the
> application freezes. The following happens:
>
> > $return_value = exec('path_to_exe_file');
> echo $return_value;
> ?>
>
> Well, the exec is executed (I can see that, the exe fil does what it
> has to do). But it doesnt return to the php-script. The php-script
> waits infinitely that the app will return, but it will not return. At
> a certain point the time execution exeedes.
>
> If I go to the command line and execute an exe file (the same one that
> exec calls), then it works without problem, and returns immediatly.
> But from the exec call it doesnt return.
>
> How do I solve this? Well, I restart the server. And hen everything
> works again. Which means that the script can use exec again without
> waiting infinitely.
>
> When the problems begin (when the exec begins to fail) the server can
> still work without problem. All the scripts run. The only scripts that
> dont run are those that have the exec call inside.
>
> error.log doesnt says anything about this.
>
> Im running apache 2.X on windows server 2003. PHP version is 5.x.
>
> I have put log function before and after every single call to exec. I
> analyzed it, but I can not understand why the exec fails. It only
> stops to get back the return value from the c# app. The c# app can
> also be a simple one with only a console.write (something like echo).
> But when exec has hanged up neither that will work.
>
> Someone can see the problem?

First, what kind of program are you calling? Whats it do?
Second, please tell me you looked up Exec on the php.net site and read
all the comments made by folks who have done or attempted to do what
you are trying. The answer might be right there!
Third, what kind of resources does the called program use? Are you
running out of memory? are you running out of connections to a
database? What is your take on why the program is failing? What
permissions does the called program have? What permsissions does it
need?

Re: exec php

am 23.12.2007 18:35:13 von warth33

> First, what kind of program are you calling? =A0Whats it do?
Its a few programs, made in c#. The programs mostly make operations on
the windows media server. They create publishing point, for example,
on the fly.

> Second, please tell me you looked up Exec on the php.net site and read
> all the comments made by folks who have done or attempted to do what
> you are trying. =A0The answer might be right there!

I had a look there. But no one that got the same king of problem.

> Third, what kind of resources does the called program use? =A0Are you
> running out of memory? =A0are you running out of connections to a
> database? =A0What is your take on why the program is failing? =A0What
> permissions does the called program have? =A0What permsissions does it
> need?-
>

I put log functions both in the php-script and in the c# app.

I restart the server, and everything works. But then, after may one
day, for some reason, one of the c# app (can be any of them) freezes
during the execution, and before it can returns.

The php-log says that, well, nothing. It stops when it has to show the
return value got from the c# app.

The C# app doesnt catch. That is the big problem. The log function in
the c# app is located at the end of the try statement. And exactly
before the return statement. In the log file I try to write the return
value. But it is blank, for some reason.

Worst of all, maybe, is that the c# app is runnable from the command
line. Always. And it executes returning the value. So the problem, as
I see it, is that suddenly the php-interpretor hangs up when running
exec.

Yes, this is obvious, as I created a dummy c# app, one that only
returns hello world. Well, after the php-interpretor (or is it apache
stuff?) hangs up, I cannot either get the return value from that app.

Is it an apache problem? What do you think guys? But the error log
doesnt have any trace of problems with the exec...

Re: exec php

am 24.12.2007 01:35:42 von Csaba Gabor

On Dec 23, 9:35 am, wart...@hotmail.com wrote:
> > First, what kind of program are you calling? Whats it do?
>
> Its a few programs, made in c#. The programs mostly make operations on
> the windows media server. They create publishing point, for example,
> on the fly.
>
> > Second, please tell me you looked up Exec on the php.net site and read
> > all the comments made by folks who have done or attempted to do what
> > you are trying. The answer might be right there!
>
> I had a look there. But no one that got the same king of problem.
>
> > Third, what kind of resources does the called program use? Are you
> > running out of memory? are you running out of connections to a
> > database? What is your take on why the program is failing? What
> > permissions does the called program have? What permsissions does it
> > need?-
>
> I put log functions both in the php-script and in the c# app.
>
> I restart the server, and everything works. But then, after may one
> day, for some reason, one of the c# app (can be any of them) freezes
> during the execution, and before it can returns.
>
> The php-log says that, well, nothing. It stops when it has to show the
> return value got from the c# app.
>
> The C# app doesnt catch. That is the big problem. The log function in
> the c# app is located at the end of the try statement. And exactly
> before the return statement. In the log file I try to write the return
> value. But it is blank, for some reason.
>
> Worst of all, maybe, is that the c# app is runnable from the command
> line. Always. And it executes returning the value. So the problem, as
> I see it, is that suddenly the php-interpretor hangs up when running
> exec.
>
> Yes, this is obvious, as I created a dummy c# app, one that only
> returns hello world. Well, after the php-interpretor (or is it apache
> stuff?) hangs up, I cannot either get the return value from that app.
>
> Is it an apache problem? What do you think guys? But the error log
> doesnt have any trace of problems with the exec...

There could be several reasons for this behaviour which are not at all
obvious in my opinion. Here is possibility.

It is possible to schedule Firefox to come up on a specific page (this
type of scheduling is non trivial), and then if you have GreaseMonkey
(GM) installed, it would do its thing and then shut down. For
example, you could monitor a web site in this way. At the end, GM
should tell the window to close itself, thus ending the scheduled app.

When I first developed this, it worked finen under manual testing,
only FF would ask me each time whether I really wanted to shut down
(there is a preference setting to control this). When the task was
automated and run under SYSTEM, I would again be asked whether I
really wanted to exit. Since I could not respond to that dialog
(since it wasn't visible), there was no way for the program to finish,
so it didn't (yet it had run fine till the end).

The moral is that it might be that your program under certain
circumstances pops up a dialog that no one is there to dismiss. That
could be a possible explanation to what is happening.

Csaba Gabor from Vancouver

Re: exec php

am 24.12.2007 01:41:20 von My Pet Programmer

Csaba Gabor said:
> On Dec 23, 9:35 am, wart...@hotmail.com wrote:
>>> First, what kind of program are you calling? Whats it do?
>> Its a few programs, made in c#. The programs mostly make operations on
>> the windows media server. They create publishing point, for example,
>> on the fly.
>>
>>> Second, please tell me you looked up Exec on the php.net site and read
>>> all the comments made by folks who have done or attempted to do what
>>> you are trying. The answer might be right there!
>> I had a look there. But no one that got the same king of problem.
>>
>>> Third, what kind of resources does the called program use? Are you
>>> running out of memory? are you running out of connections to a
>>> database? What is your take on why the program is failing? What
>>> permissions does the called program have? What permsissions does it
>>> need?-
>> I put log functions both in the php-script and in the c# app.
>>
>> I restart the server, and everything works. But then, after may one
>> day, for some reason, one of the c# app (can be any of them) freezes
>> during the execution, and before it can returns.
>>
>> The php-log says that, well, nothing. It stops when it has to show the
>> return value got from the c# app.
>>
>> The C# app doesnt catch. That is the big problem. The log function in
>> the c# app is located at the end of the try statement. And exactly
>> before the return statement. In the log file I try to write the return
>> value. But it is blank, for some reason.
>>
>> Worst of all, maybe, is that the c# app is runnable from the command
>> line. Always. And it executes returning the value. So the problem, as
>> I see it, is that suddenly the php-interpretor hangs up when running
>> exec.
>>
>> Yes, this is obvious, as I created a dummy c# app, one that only
>> returns hello world. Well, after the php-interpretor (or is it apache
>> stuff?) hangs up, I cannot either get the return value from that app.
>>
>> Is it an apache problem? What do you think guys? But the error log
>> doesnt have any trace of problems with the exec...
>
> There could be several reasons for this behaviour which are not at all
> obvious in my opinion. Here is possibility.
>
> It is possible to schedule Firefox to come up on a specific page (this
> type of scheduling is non trivial), and then if you have GreaseMonkey
> (GM) installed, it would do its thing and then shut down. For
> example, you could monitor a web site in this way. At the end, GM
> should tell the window to close itself, thus ending the scheduled app.
>
> When I first developed this, it worked finen under manual testing,
> only FF would ask me each time whether I really wanted to shut down
> (there is a preference setting to control this). When the task was
> automated and run under SYSTEM, I would again be asked whether I
> really wanted to exit. Since I could not respond to that dialog
> (since it wasn't visible), there was no way for the program to finish,
> so it didn't (yet it had run fine till the end).
>
> The moral is that it might be that your program under certain
> circumstances pops up a dialog that no one is there to dismiss. That
> could be a possible explanation to what is happening.
>
> Csaba Gabor from Vancouver

A while back, I had to write some code that called on Perl2exe on the
server to compile Perl modules. What I ran into was an issue where I had
to set the paths appropriately on the box by first executing a shell
script from php that set up the enironment for my command.

Could it be something like that?

~A!

Re: exec php

am 24.12.2007 17:41:59 von Csaba Gabor

On Dec 23, 4:41 pm, My Pet Programmer
wrote:
> Csaba Gabor said:
....
> >> Is it an apache problem? What do you think guys? But the error log
> >> doesnt have any trace of problems with the exec...
>
> > There could be several reasons for this behaviour which are not at all
> > obvious in my opinion. Here is possibility.
>
> > It is possible to schedule Firefox to come up on a specific page (this
> > type of scheduling is non trivial), and then if you have GreaseMonkey
> > (GM) installed, it would do its thing and then shut down. For
> > example, you could monitor a web site in this way. At the end, GM
> > should tell the window to close itself, thus ending the scheduled app.
>
> > When I first developed this, it worked finen under manual testing,
> > only FF would ask me each time whether I really wanted to shut down
> > (there is a preference setting to control this). When the task was
> > automated and run under SYSTEM, I would again be asked whether I
> > really wanted to exit. Since I could not respond to that dialog
> > (since it wasn't visible), there was no way for the program to finish,
> > so it didn't (yet it had run fine till the end).
>
> > The moral is that it might be that your program under certain
> > circumstances pops up a dialog that no one is there to dismiss. That
> > could be a possible explanation to what is happening.
>
> > Csaba Gabor from Vancouver
>
> A while back, I had to write some code that called on Perl2exe on the
> server to compile Perl modules. What I ran into was an issue where I had
> to set the paths appropriately on the box by first executing a shell
> script from php that set up the enironment for my command.
>
> Could it be something like that?
>
> ~A!

"something like that" covers a lot of ground. It could have some
bearing, though it is not obvious. Firstly, you are saying that the
program does what it should do. That would imply that the paths/
environment vars are correct. However, if it affects the cleanup of
the program somehow it could be material. Also, it might be affected
by the "Allow service to interact with desktop" setting that you can
make on Apache/your web server (under Control Panel \ Services).

Csaba

Re: exec php

am 24.12.2007 17:48:38 von My Pet Programmer

Csaba Gabor said:

> "something like that" covers a lot of ground. It could have some
> bearing, though it is not obvious. Firstly, you are saying that the
> program does what it should do. That would imply that the paths/
> environment vars are correct. However, if it affects the cleanup of
> the program somehow it could be material. Also, it might be affected
> by the "Allow service to interact with desktop" setting that you can
> make on Apache/your web server (under Control Panel \ Services).
>
> Csaba

Gotta love the ambiguous errors. I don't think he said it does what it
should do, though. I know when I ran exec without the paths right, I
didn't get any server errors either, and I had the same kind of issue
he's describing.

So it might cover a lot of ground, but it's kinda always better to have
a bunch of ideas, no matter how much they cover, I tink.

~A!

Re: exec php

am 24.12.2007 19:51:30 von warth33

On 24 Dec, 08:48, My Pet Programmer
wrote:
> Csaba Gabor said:
>
> > "something like that" covers a lot of ground. =A0It could have some
> > bearing, though it is not obvious. =A0Firstly, you are saying that the
> > program does what it should do. =A0That would imply that the paths/
> > environment vars are correct. =A0However, if it affects the cleanup of
> > the program somehow it could be material. =A0Also, it might be affected
> > by the "Allow service to interact with desktop" setting that you can
> > make on Apache/your web server (under Control Panel \ Services).
>
> > Csaba
>
> Gotta love the ambiguous errors. I don't think he said it does what it
> should do, though. I know when I ran exec without the paths right, I
> didn't get any server errors either, and I had the same kind of issue
> he's describing.
>
> So it might cover a lot of ground, but it's kinda always better to have
> a bunch of ideas, no matter how much they cover, I tink.
>
> ~A!

Yes, the c# programs do what they have to do. They work! They work 2
hours, 3 hours, maybe 1 day. And then suddenly it stops to work.

It is extrmly frustating. I have tried to put logs both in the php-
script and in the c# app. Nothing. Not an exception. Nothing.

Again: if I have a simple C# app that only have an Hello World, then
the php script, or to be more exact the exec call from the php-script
to the c# app, seems like going in an infinite loop. Even thought
there is no loop there. The exec waits, for ever...

No error in error.log fo r apache. And, no problem in continuing with
running the server. I can always view other pages. The only problem, a
very big problem, is that at a certain point the exec function hangs
up.

Re: exec php

am 24.12.2007 20:00:32 von warth33

On 24 Dec, 10:51, wart...@hotmail.com wrote:
> On 24 Dec, 08:48, My Pet Programmer
> wrote:
>
>
>
>
>
> > Csaba Gabor said:
>
> > > "something like that" covers a lot of ground. =A0It could have some
> > > bearing, though it is not obvious. =A0Firstly, you are saying that the=

> > > program does what it should do. =A0That would imply that the paths/
> > > environment vars are correct. =A0However, if it affects the cleanup of=

> > > the program somehow it could be material. =A0Also, it might be affecte=
d
> > > by the "Allow service to interact with desktop" setting that you can
> > > make on Apache/your web server (under Control Panel \ Services).
>
> > > Csaba
>
> > Gotta love the ambiguous errors. I don't think he said it does what it
> > should do, though. I know when I ran exec without the paths right, I
> > didn't get any server errors either, and I had the same kind of issue
> > he's describing.
>
> > So it might cover a lot of ground, but it's kinda always better to have
> > a bunch of ideas, no matter how much they cover, I tink.
>
> > ~A!
>
> Yes, the c# programs do what they have to do. They work! They work 2
> hours, 3 hours, maybe 1 day. And then suddenly it stops to work.
>
> It is extrmly frustating. I have tried to put logs both in the php-
> script and in the c# app. Nothing. Not an exception. Nothing.
>
> Again: if I have a simple C# app that only have an Hello World, then
> the php script, or to be more exact the exec call from the php-script
> to the c# app, seems like going in an infinite loop. Even thought
> there is no loop there. The exec waits, for ever...
>
> No error in error.log fo r apache. And, no problem in continuing with
> running the server. I can always view other pages. The only problem, a
> very big problem, is that at a certain point the exec function hangs
> up.- Dölj citerad text -
>
> - Visa citerad text -

Maybe another intresting thing.

The c# app that I try to run after exec begins to freeze, looks
something like that:

static void Main(string[] args){
tw.WriteLine("Before at " + DateTime.Now);
Console.Write("error test");
tw.WriteLine("After at " + DateTime.Now);
tw.Close();
}

In the c# app there is nothing else than this. The funny thing is that
in the log can see:

Before at (date)
After at (date)

Console.writeline should have been executed right? It is stated before
the second log line...

Re: exec php

am 27.12.2007 14:14:36 von warth33

I am quite sure that the problem is located in the function exec. At
some point, that function hangs up. Why? Not easy to know. But is it
possible to log it? Ordinary self made log function doesnt give
anything. Apache error log doesnt give anything either. How can I
analyze what is going on with that function?

Re: exec php

am 27.12.2007 14:21:25 von My Pet Programmer

warth33@hotmail.com said:
> I am quite sure that the problem is located in the function exec. At
> some point, that function hangs up. Why? Not easy to know. But is it
> possible to log it? Ordinary self made log function doesnt give
> anything. Apache error log doesnt give anything either. How can I
> analyze what is going on with that function?
>
If they work for a while and then suddenly stop, have you checked the OS
error logs? If there is an error happening, it's going to be recorded
somewhere. It could be something as simple as your app filling up memory
somehow, or having too many open threads to it from the OS' viewpoint.

With exec, if it goes out and executes successfully once, then it's most
likely not broken there, and you might need to go deeper to get to any
kind of issues. Maybe open up the server process list and watch what's
happening while it runs, if you can.


Good luck, chasing this one is going to cost you a bunch of time, sounds
like.
~A!

--
Anthony Levensalor
anthony@mypetprogrammer.com

Re: exec php

am 28.12.2007 02:57:16 von Jerry Stuckle

Betikci Boris wrote:
> On Dec 21, 3:01 pm, wart...@hotmail.com wrote:
>> Hello
>>
>> I have a php site. Some page needs to call an external program. The
>> programs are home made c# applications.
>>
>> It uses to work without problem. For a while. Maybe it work for some
>> hour. Or for a day. Or even for a week.
>>
>> At a certain point, when a php script calls the exe file, the
>> application freezes. The following happens:
>>
>> >> $return_value = exec('path_to_exe_file');
>> echo $return_value;
>> ?>
>>
>> Well, the exec is executed (I can see that, the exe fil does what it
>> has to do). But it doesnt return to the php-script. The php-script
>> waits infinitely that the app will return, but it will not return. At
>> a certain point the time execution exeedes.
>>
>> If I go to the command line and execute an exe file (the same one that
>> exec calls), then it works without problem, and returns immediatly.
>> But from the exec call it doesnt return.
>>
>> How do I solve this? Well, I restart the server. And hen everything
>> works again. Which means that the script can use exec again without
>> waiting infinitely.
>>
>> When the problems begin (when the exec begins to fail) the server can
>> still work without problem. All the scripts run. The only scripts that
>> dont run are those that have the exec call inside.
>>
>> error.log doesnt says anything about this.
>>
>> Im running apache 2.X on windows server 2003. PHP version is 5.x.
>>
>> I have put log function before and after every single call to exec. I
>> analyzed it, but I can not understand why the exec fails. It only
>> stops to get back the return value from the c# app. The c# app can
>> also be a simple one with only a console.write (something like echo).
>> But when exec has hanged up neither that will work.
>>
>> Someone can see the problem?
>
> Bad combination! Apache server on Windows 2003 server. Thy combination
> really diminishes the performance and may cause those freezes
>
> You should switch to GNU/Linux-Apache/php or Windows2003/IIS/Asp.NET
>
>

Horse hockey. Apache runs quite well on Windows - much better than IIS does.

But I do agree Linux is a better os.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: exec php

am 28.12.2007 03:04:59 von Jerry Stuckle

warth33@hotmail.com wrote:
> On 24 Dec, 10:51, wart...@hotmail.com wrote:
>> On 24 Dec, 08:48, My Pet Programmer
>> wrote:
>>
>>
>>
>>
>>
>>> Csaba Gabor said:
>>>> "something like that" covers a lot of ground. It could have some
>>>> bearing, though it is not obvious. Firstly, you are saying that the
>>>> program does what it should do. That would imply that the paths/
>>>> environment vars are correct. However, if it affects the cleanup of
>>>> the program somehow it could be material. Also, it might be affected
>>>> by the "Allow service to interact with desktop" setting that you can
>>>> make on Apache/your web server (under Control Panel \ Services).
>>>> Csaba
>>> Gotta love the ambiguous errors. I don't think he said it does what it
>>> should do, though. I know when I ran exec without the paths right, I
>>> didn't get any server errors either, and I had the same kind of issue
>>> he's describing.
>>> So it might cover a lot of ground, but it's kinda always better to have
>>> a bunch of ideas, no matter how much they cover, I tink.
>>> ~A!
>> Yes, the c# programs do what they have to do. They work! They work 2
>> hours, 3 hours, maybe 1 day. And then suddenly it stops to work.
>>
>> It is extrmly frustating. I have tried to put logs both in the php-
>> script and in the c# app. Nothing. Not an exception. Nothing.
>>
>> Again: if I have a simple C# app that only have an Hello World, then
>> the php script, or to be more exact the exec call from the php-script
>> to the c# app, seems like going in an infinite loop. Even thought
>> there is no loop there. The exec waits, for ever...
>>
>> No error in error.log fo r apache. And, no problem in continuing with
>> running the server. I can always view other pages. The only problem, a
>> very big problem, is that at a certain point the exec function hangs
>> up.- Dölj citerad text -
>>
>> - Visa citerad text -
>
> Maybe another intresting thing.
>
> The c# app that I try to run after exec begins to freeze, looks
> something like that:
>
> static void Main(string[] args){
> tw.WriteLine("Before at " + DateTime.Now);
> Console.Write("error test");
> tw.WriteLine("After at " + DateTime.Now);
> tw.Close();
> }
>
> In the c# app there is nothing else than this. The funny thing is that
> in the log can see:
>
> Before at (date)
> After at (date)
>
> Console.writeline should have been executed right? It is stated before
> the second log line...
>

The problem isn't in your exec() call. Rather, (from an earlier post)
you need to find out why your program is not returning a value.

exec() works quite well. I've never found a problem in it - although I
have found problems in my code at times.

As for the Console.writeline - try a C# newsgroup.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: exec php

am 17.01.2008 11:25:01 von warth33

Oh well. In the C# newsgroup no one could help me. They dont seem to
have any idea o nwhat is going on. I tryed to explain the problem as
detailed as possible, but nothing..
Today I tryed something quite basic. It sounded as it was a good
solution, so bad that I hadnt tried it before. Setting time limit. The
thing was that the time limit in php ini is set to 0 on the server.

So I put this in a test script:

set_time_limit(10);
try{
echo 'before exec';
log('before exec');
$ret = exec('path_to_exx_file.exe');
echo 'exec returned ' . $ret;
log('exec returned ' . $ret);
}
catch(Exception $e){
echo 'failed due to: ' . $e;
log('failed due to: ' . $e);
}

Note that this script was calling a simple Hello world c# program.

But neither this helped me. The script will run for ever.

Is there really not anyone that can help me out, just give me some
good hint of what the problem can be? Arent they any gurus there out??

Re: exec php

am 17.01.2008 14:59:36 von Jerry Stuckle

warth33@hotmail.com wrote:
> Oh well. In the C# newsgroup no one could help me. They dont seem to
> have any idea o nwhat is going on. I tryed to explain the problem as
> detailed as possible, but nothing..
> Today I tryed something quite basic. It sounded as it was a good
> solution, so bad that I hadnt tried it before. Setting time limit. The
> thing was that the time limit in php ini is set to 0 on the server.
>
> So I put this in a test script:
>
> set_time_limit(10);
> try{
> echo 'before exec';
> log('before exec');
> $ret = exec('path_to_exx_file.exe');
> echo 'exec returned ' . $ret;
> log('exec returned ' . $ret);
> }
> catch(Exception $e){
> echo 'failed due to: ' . $e;
> log('failed due to: ' . $e);
> }
>
> Note that this script was calling a simple Hello world c# program.
>
> But neither this helped me. The script will run for ever.
>
> Is there really not anyone that can help me out, just give me some
> good hint of what the problem can be? Arent they any gurus there out??
>
>

PHP can only time out when it is in control. Once it passes control off
to the C# program, PHP can't time out until control is returned.

And there are PHP gurus here. But this isn't a PHP problem - PHP isn't
even involved after the call to exec().

But I also sympathize with you. These things aren't easy to find.

Maybe start a little more basic. What happens if you just have a C#
program which does nothing but return? What if you don't have any
output from the C# program?

BTW - posting your C# code here won't help. Most of us won't understand
it, anyway.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: exec php

am 17.01.2008 15:46:23 von warth33

> PHPcan only time out when it is in control. =A0Once it passes control off
> to the C# program,PHPcan't time out until control is returned.
>
> And there arePHPgurus here. =A0But this isn't aPHPproblem -PHPisn't
> even involved after the call to exec().
>
> But I also sympathize with you. =A0These things aren't easy to find.
>
> Maybe start a little more basic. =A0What happens if you just have a C#
> program which does nothing but return? =A0What if you don't have any
> output from the C# program?
>
> BTW - posting your C# code here won't help. =A0Most of us won't understand=

> it, anyway.
>

Thank for the support Jerry. I was just a little bit frustrated, thats
why I told that think about gurus.
Well I will try to call a c# that doesnt return anything. And I will
see if exec runs forever even in that case. Im just waiting for the
next time the server hangs up, which will happen in the next few hours
or next few days (I think the site web application worked without
hanging up for more than a couple of days). I'll be back soon..

Re: exec php

am 17.01.2008 21:42:14 von warth33

Here we are. The problem showed up again. The php script looks like
this:

***********************************
set_time_limit(20);
write_to_log("Beginning at " . date('Y-m-d H:i:s'));
$exec_command = 'app.exe';
$str = "Before at " . date('Y-m-d H:i:s');
write_to_log("Before at " . date('Y-m-d H:i:s'));
try {
write_to_log("trying at " . date('Y-m-d H:i:s'));
exec($exec_command);
write_to_log("after execution at " . date('Y-m-d H:i:s'));
write_to_log("Ends at " . date('Y-m-d H:i:s'));
}
catch (Exception $e) {
write_to_log("message was " . $e->getMessage());
}
***********************************

The log file, when everything works, contains this:

***********************************
Beginning at 2008-01-17 19:02:09
Before at 2008-01-17 19:02:09
trying at 2008-01-17 19:02:09
after execution at 2008-01-17 19:02:09
Ends at 2008-01-17 19:02:09
***********************************

The log file, when it hangs up, contains this:

***********************************
Beginning at 2008-01-17 21:10:52
Before at 2008-01-17 21:10:52
trying at 2008-01-17 21:10:52
***********************************

I used another c# app, a one that doesnt return anything. But the exec
still hangs up. Most people here dont know anything about c#, but
Ipost it cause its very simple stuff, and I think every programmer
should understand it, even if it is a different syntax:

***********************************
static void Main(string[] args){
TextWriter tw = new StreamWriter("C:\\logs\\app.txt",
true);
tw.WriteLine("beginning at " + DateTime.Now);
tw.WriteLine("ending at " + DateTime.Now);
tw.Close();
}
***********************************

The app is only writing to the log file. And is not printing anything
to the console (which corresponds to the return value that the php
script use to get).

The log file for the c# app, when everything works, looks like this:

***********************************
beginning at 2008-01-17 21:10:52
ending at 2008-01-17 21:10:52
***********************************

And, the funny thing, it looks exactly the same, even after the exec
hangs up. The c# is executed, always, when called from php through
php. But, when saying that exec is hanging up, it means that it doesnt
return. Thats all.

Re: exec php

am 18.01.2008 00:08:04 von warth33

This is a php group, most people dont know about c#. So my question, a
php-related one, is: what strategy would you use n this case? To solve
the problem, or at least to do something about this. I mean, you have
a few php-scripts whose execution is dependent on an external program.
What would you do in a case like this? When ou know that sometimes the
execution can fail (and worst of all make, more or less, a whole web
app to hang up), and you just want to exit, in those cases? What would
you do, guys?
As Jerry said, the try and catch will not work, as php will loose the
control when the exec will be called.

Re: exec php

am 18.01.2008 01:51:44 von Jerry Stuckle

warth33@hotmail.com wrote:
> Here we are. The problem showed up again. The php script looks like
> this:
>
> ***********************************
> set_time_limit(20);
> write_to_log("Beginning at " . date('Y-m-d H:i:s'));
> $exec_command = 'app.exe';
> $str = "Before at " . date('Y-m-d H:i:s');
> write_to_log("Before at " . date('Y-m-d H:i:s'));
> try {
> write_to_log("trying at " . date('Y-m-d H:i:s'));
> exec($exec_command);
> write_to_log("after execution at " . date('Y-m-d H:i:s'));
> write_to_log("Ends at " . date('Y-m-d H:i:s'));
> }
> catch (Exception $e) {
> write_to_log("message was " . $e->getMessage());
> }
> ***********************************
>
> The log file, when everything works, contains this:
>
> ***********************************
> Beginning at 2008-01-17 19:02:09
> Before at 2008-01-17 19:02:09
> trying at 2008-01-17 19:02:09
> after execution at 2008-01-17 19:02:09
> Ends at 2008-01-17 19:02:09
> ***********************************
>
> The log file, when it hangs up, contains this:
>
> ***********************************
> Beginning at 2008-01-17 21:10:52
> Before at 2008-01-17 21:10:52
> trying at 2008-01-17 21:10:52
> ***********************************
>
> I used another c# app, a one that doesnt return anything. But the exec
> still hangs up. Most people here dont know anything about c#, but
> Ipost it cause its very simple stuff, and I think every programmer
> should understand it, even if it is a different syntax:
>
> ***********************************
> static void Main(string[] args){
> TextWriter tw = new StreamWriter("C:\\logs\\app.txt",
> true);
> tw.WriteLine("beginning at " + DateTime.Now);
> tw.WriteLine("ending at " + DateTime.Now);
> tw.Close();
> }
> ***********************************
>
> The app is only writing to the log file. And is not printing anything
> to the console (which corresponds to the return value that the php
> script use to get).
>
> The log file for the c# app, when everything works, looks like this:
>
> ***********************************
> beginning at 2008-01-17 21:10:52
> ending at 2008-01-17 21:10:52
> ***********************************
>
> And, the funny thing, it looks exactly the same, even after the exec
> hangs up. The c# is executed, always, when called from php through
> php. But, when saying that exec is hanging up, it means that it doesnt
> return. Thats all.
>

Interesting. So the C# program writes its final log entry and something
hangs.

I would say it's in one of two places - either the C# program, or, more
likely, Windows. The reason I say the latter is because your C# program
just goes through its termination code and back to Windows. Windows
should then return control to PHP.

It doesn't look like this last part is getting done - there isn't a lot
for PHP to do before it continues execution of your program.

Is there anything in your Event Logs showing a problem? Can you still
see the C# process running in the system?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: exec php

am 18.01.2008 11:35:47 von warth33

> Interesting. =A0So the C# program writes its final log entry and something=

> hangs.
>
> I would say it's in one of two places - either the C# program, or, more
> likely, Windows. =A0The reason I say the latter is because your C# program=

> just goes through its termination code and back to Windows. =A0Windows
> should then return control toPHP.
>
> It doesn't look like this last part is getting done - there isn't a lot
> forPHPto do before it continues execution of your program.
>
> Is there anything in your Event Logs showing a problem? =A0Can you still
> see the C# process running in the system?

Well, It happened again now. So I opened the task manager. Among the
processes there was not any of the c# programs. Then I had a looko at
the event logs. I dont know much about it, so I googled and it seems
that the command eventwvr opens the log im intresting in.

It showes a lot of errors, but I could not find one that was related
to any c# programs. I think I will research a little about detecting
errors of aplpication in the windows log.

Re: exec php

am 18.01.2008 12:53:58 von Jerry Stuckle

warth33@hotmail.com wrote:
>> Interesting. So the C# program writes its final log entry and something
>> hangs.
>>
>> I would say it's in one of two places - either the C# program, or, more
>> likely, Windows. The reason I say the latter is because your C# program
>> just goes through its termination code and back to Windows. Windows
>> should then return control toPHP.
>>
>> It doesn't look like this last part is getting done - there isn't a lot
>> forPHPto do before it continues execution of your program.
>>
>> Is there anything in your Event Logs showing a problem? Can you still
>> see the C# process running in the system?
>
> Well, It happened again now. So I opened the task manager. Among the
> processes there was not any of the c# programs. Then I had a looko at
> the event logs. I dont know much about it, so I googled and it seems
> that the command eventwvr opens the log im intresting in.
>
> It showes a lot of errors, but I could not find one that was related
> to any c# programs. I think I will research a little about detecting
> errors of aplpication in the windows log.
>
>

The problem is it may not be directly related to the C# application. It
could be something in the system, the C# libraries or about anything.

And you should be able to find your event viewer under "Administrative
tools". It's not necessarily bad to have some entries, i.e. Windows
will place startup messages in there. But you do need to at least
understand the cause of the errors, if not fix them.

Check a Windows newsgroup for more info here.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: exec php

am 19.01.2008 14:09:32 von Csaba Gabor

On Jan 18, 12:08 am, wart...@hotmail.com wrote:
> This is a php group, most people dont know about c#. So my question, a
> php-related one, is: what strategy would you use n this case? To solve
> the problem, or at least to do something about this. I mean, you have
> a few php-scripts whose execution is dependent on an external program.
> What would you do in a case like this? When ou know that sometimes the
> execution can fail (and worst of all make, more or less, a whole web
> app to hang up), and you just want to exit, in those cases? What would
> you do, guys?
> As Jerry said, the try and catch will not work, as php will loose the
> control when the exec will be called.

Given your seemingly random, but consisent failure,
here is a possible approach (but I'd look at popen below, first):

In your php program, create a scheduled task whose only function
will be to execute your exec right away (this can either be
done by scheduling the task to run at the top of the next minute
or schtasks can explicitly cause the task to run (but it
requires a one line exec call) - you must ensure a unique
id). This way your original program is not
tied to the completion of your scheduled script.
The scheduled script (or rather, whatever is execed) could write
a file or leave some tracks for the original script to detect
that it has gotten sufficiently far if that's a requirement.

You have a few ways of going about this. On Windows, you can
use either AT or SchTasks. The latter may be worked with as a
COM object (otherwise you'll be looking at some version of exec).

---------

Also, as regards your exec, something I would investigate
before total frustration (if that point hasn't already been
reached) is a http://php.net/popen variant. By the way,
the exec family of functions (or something related to them)
was revised over the last year especially in regards to
being executed from php-win.exe so it's probably a good
idea to have a recent copy of php.

Csaba Gabor from Vienna

Re: exec php

am 20.01.2008 13:29:45 von warth33

> Given your seemingly random, but consisent failure,
> here is a possible approach (but I'd look at popen below, first):
>
> In yourphpprogram, create a scheduled task whose only function
> will be to execute your exec right away (this can either be
> done by scheduling the task to run at the top of the next minute
> or schtasks can explicitly cause the task to run (but it
> requires a one line exec call) - you must ensure a unique
> id). =A0This way your original program is not
> tied to the completion of your scheduled script.
> The scheduled script (or rather, whatever is execed) could write
> a file or leave some tracks for the original script to detect
> that it has gotten sufficiently far if that's a requirement.
>
> You have a few ways of going about this. =A0On Windows, you can
> use either AT or SchTasks. =A0The latter may be worked with as a
> COM object (otherwise you'll be looking at some version of exec).
>

I must confess I dont really understand how to implement this, and
neither know if this is something for me. I mean the kind of webapp I
have will probably not gain benefits by using this approach.

> Also, as regards your exec, something I would investigate
> before total frustration (if that point hasn't already been
> reached) is ahttp://php.net/popenvariant. =A0By the way,
> the exec family of functions (or something related to them)
> was revised over the last year especially in regards to
> being executed fromphp-win.exe so it's probably a good
> idea to have a recent copy ofphp.

Yes I will try this too. When the exec hangs up I will try to call a
test php-script that, in turn, only calls a dummy c# app, one that
only prints hello world. If it will not help, I think I will try to
replace all my calls to exec with popen. And see if that will help...
Anyway the first thing I will do is to replace the php-copy with a
newer one(it is 5.2.1 now). Cause I reallt dont know how to face this
problem anymore. Thanks all for the help, will be back in case of
better news.

Re: exec php

am 21.01.2008 22:03:40 von warth33

Ok, an interesting thing. The exec hanged up now. But I was not
inlogged. This time I opened task manager and selected "Show process
from all user" (should have done this before).

Now I can see what is going on. It was not difficult to guess, but at
least I have seen that now. Everytime, after the exec begins to give
problems, the exec is called, then I can see in the task manager that
there is one of the processes called by exec running. So If I open the
browser and go to: test.php, that in turn will do exec (hello.exe), a
new process is added in the task manager, so right now I have a lot of
hello.exe running...

Re: exec php

am 21.01.2008 23:18:39 von Jerry Stuckle

warth33@hotmail.com wrote:
> Ok, an interesting thing. The exec hanged up now. But I was not
> inlogged. This time I opened task manager and selected "Show process
> from all user" (should have done this before).
>
> Now I can see what is going on. It was not difficult to guess, but at
> least I have seen that now. Everytime, after the exec begins to give
> problems, the exec is called, then I can see in the task manager that
> there is one of the processes called by exec running. So If I open the
> browser and go to: test.php, that in turn will do exec (hello.exe), a
> new process is added in the task manager, so right now I have a lot of
> hello.exe running...
>

So your hello.exe isn't terminating. I guess you need to find out why
next. PHP won't continue until the exe finishes, of course.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: exec php

am 21.01.2008 23:51:55 von warth33

> So your hello.exe isn't terminating. =A0I guess you need to find out why
> next. =A0PHPwon't continue until the exe finishes, of course.
>
yes, hello wolrd is not terminating. Well, hehe, why?
The custommized php error log doesnt show anything, and its quite
normal if it doesnt, yes.
The customized c# error log doesnt catch, execute until the end, and
doesnt report any error in the log.
The apache error log DOES NOT show anything wrong.
The windows event log DOESN NOT log error inprogram execution, sigh

The only thing I can work with right now, is the memory leak, if there
is a memory leak. I guess I have to ask in an apache group. But, I try
to ask it here also:

When starting apache, the values retrieved from windows task manager
are:

Mem usage: 16 968 K
VM size: 16 696 K
Handles: 705


After about a day, the values are:

httpd.exe
Mem usage: 58 123 K
VM size: 67 676 K
Handles: 829

Does this sound wrong?

Re: exec php

am 22.01.2008 00:00:26 von Jerry Stuckle

warth33@hotmail.com wrote:
>> So your hello.exe isn't terminating. I guess you need to find out why
>> next. PHPwon't continue until the exe finishes, of course.
>>
> yes, hello wolrd is not terminating. Well, hehe, why?
> The custommized php error log doesnt show anything, and its quite
> normal if it doesnt, yes.
> The customized c# error log doesnt catch, execute until the end, and
> doesnt report any error in the log.
> The apache error log DOES NOT show anything wrong.
> The windows event log DOESN NOT log error inprogram execution, sigh
>
> The only thing I can work with right now, is the memory leak, if there
> is a memory leak. I guess I have to ask in an apache group. But, I try
> to ask it here also:
>
> When starting apache, the values retrieved from windows task manager
> are:
>
> Mem usage: 16 968 K
> VM size: 16 696 K
> Handles: 705
>
>
> After about a day, the values are:
>
> httpd.exe
> Mem usage: 58 123 K
> VM size: 67 676 K
> Handles: 829
>
> Does this sound wrong?
>
>

I have no idea. There are way more things going on in the system than
just Apache and PHP.

What you need to do is work with the MS admin and/or C# people to
determine why the program isn't terminating. There isn't anything PHP
can do about it.

I'm not trying to put you off here - but you need to solve the problem
of why your C# program isn't terminating. And that's way outside the
purpose of this newsgroup. Plus I doubt there are many who could help
you with it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: exec php

am 22.01.2008 00:41:06 von warth33

On 22 Jan, 00:00, Jerry Stuckle wrote:
> wart...@hotmail.com wrote:
> >> So your hello.exe isn't terminating. =A0I guess you need to find out wh=
y
> >> next. =A0PHPwon't continue until the exe finishes, of course.
>
> > yes, hello wolrd is not terminating. Well, hehe, why?
> > The custommizedphperror log doesnt show anything, and its quite
> > normal if it doesnt, yes.
> > The customized c# error log doesnt catch, execute until the end, and
> > doesnt report any error in the log.
> > The apache error log DOES NOT show anything wrong.
> > The windows event log DOESN NOT log error inprogram execution, sigh
>
> > The only thing I can work with right now, is the memory leak, if there
> > is a memory leak. I guess I have to ask in an apache group. But, I try
> > to ask it here also:
>
> > When starting apache, the values retrieved from windows task manager
> > are:
>
> > Mem usage: 16 968 K
> > VM size: 16 696 K
> > Handles: 705
>
> > After about a day, the values are:
>
> > httpd.exe
> > Mem usage: 58 123 K
> > VM size: 67 676 K
> > Handles: 829
>
> > Does this sound wrong?
>
> I have no idea. =A0There are way more things going on in the system than
> just Apache andPHP.
>
> What you need to do is work with the MS admin and/or C# people to
> determine why the program isn't terminating. =A0There isn't anythingPHP
> can do about it.
>
> I'm not trying to put you off here - but you need to solve the problem
> of why your C# program isn't terminating. =A0And that's way outside the
> purpose of this newsgroup. =A0Plus I doubt there are many who could help
> you with it.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================- Dölj citerad tex=
t -
>
> - Visa citerad text -

I understand, you probably right. Thank you for your time.