Memory leak occurs when exec() function is used on Windows platform

Memory leak occurs when exec() function is used on Windows platform

am 09.09.2007 17:14:29 von melmack3

Hi

I have a big problem with shell commands execution via PHP.
I have written a very short PHP script ilustrating the problem:




for($i=0;$i<1000;$i++)
{
exec("test.bat");



}


?>

test.bat is just an empty file.


This script causes about 10 MB memory leak. It can be observed
by usage of performance system monitor. This problems occurs in
all available enviroments:
- IIS Webserver.
- Apache webserver
- PHP command line interpreter


Memory leak is observable only on Windows platform
(tested on Windows XP). On Linux everything works OK.


Does someone know how to solve this problem? Any help appreciated


Best regards
Melmack

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Memory leak occurs when exec() function is used on Windows platform

am 10.09.2007 03:51:06 von Elizabeth Smith

melmack wrote:
> Hi
>
> I have a big problem with shell commands execution via PHP.
> I have written a very short PHP script ilustrating the problem:
>
>
> >
>
> for($i=0;$i<1000;$i++)
> {
> exec("test.bat");
>
>
>
> }
>
>
> ?>
>
> test.bat is just an empty file.
>
>
> This script causes about 10 MB memory leak. It can be observed
> by usage of performance system monitor. This problems occurs in
> all available enviroments:
> - IIS Webserver.
> - Apache webserver
> - PHP command line interpreter
>
>
> Memory leak is observable only on Windows platform
> (tested on Windows XP). On Linux everything works OK.
>
>
> Does someone know how to solve this problem? Any help appreciated
>
>
> Best regards
> Melmack

I've found exec to be flaky enough on windows that instead I use com to
spawn the new process.

$shell = new COM('WScript.Shell');
$return = $shell->Run($cmd, 0, false);
unset ($shell);

Faster and no leaks ;) Only downside is you have to wrap cross-platform
code with windows detection.

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Memory leak occurs when exec() function is used on Windows platform

am 10.09.2007 20:17:05 von melmack3

Thank you for your reply.
Unfortunately your method also causes memory leak.
I have tested operating system and I have discovered
that batch script listed below causes the same memory leak.
That is why I think now that it is however not PHP fault but Windows bug.

The Windows batch script contains:
for /L %%i in (1,1,500) do cmd /C test.bat

where test.bat is just an empty file.

Maybe someone knows how to solve this problem?

Best regards
Melmack


Uzytkownik "Elizabeth Smith" napisal w
wiadomosci news:F4.21.17175.2E3A4E64@pb1.pair.com...
> melmack wrote:
>> Hi
>>
>> I have a big problem with shell commands execution via PHP.
>> I have written a very short PHP script ilustrating the problem:
>>
>>
>> >>
>>
>> for($i=0;$i<1000;$i++)
>> { exec("test.bat"); } ?> test.bat is just an empty file. This script
>> causes about 10 MB memory leak. It can be observed by usage of
>> performance system monitor. This problems occurs in all available
>> enviroments: - IIS Webserver. - Apache webserver - PHP command line
>> interpreter Memory leak is observable only on Windows platform (tested on
>> Windows XP). On Linux everything works OK. Does someone know how to solve
>> this problem? Any help appreciated Best regards Melmack
>
> I've found exec to be flaky enough on windows that instead I use com to
> spawn the new process.
>
> $shell = new COM('WScript.Shell');
> $return = $shell->Run($cmd, 0, false);
> unset ($shell);
>
> Faster and no leaks ;) Only downside is you have to wrap cross-platform
> code with windows detection.

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Re: Memory leak occurs when exec() function is used on Windows platform

am 11.09.2007 08:31:00 von Gustav Wiberg

Hi!

Can't you just test if the file contains anything, and if it doesn THEN run=
exec-command?

Best regards
/Gustav Wiberg
=20

-----Original Message-----
From: Melmack [mailto:melmack3@gmail.com]=20
Sent: Monday, September 10, 2007 8:17 PM
To: php-windows@lists.php.net
Subject: [PHP-WIN] Re: Memory leak occurs when exec() function is used on W=
indows platform

Thank you for your reply.
Unfortunately your method also causes memory leak.
I have tested operating system and I have discovered
that batch script listed below causes the same memory leak.
That is why I think now that it is however not PHP fault but Windows bug.

The Windows batch script contains:
for /L %%i in (1,1,500) do cmd /C test.bat

where test.bat is just an empty file.

Maybe someone knows how to solve this problem?

Best regards
Melmack


Uzytkownik "Elizabeth Smith" napisal w=20
wiadomosci news:F4.21.17175.2E3A4E64@pb1.pair.com...
> melmack wrote:
>> Hi
>>
>> I have a big problem with shell commands execution via PHP.
>> I have written a very short PHP script ilustrating the problem:
>>
>>
>> >>
>>
>> for($i=3D0;$i<1000;$i++)
>> { exec("test.bat"); } ?> test.bat is just an empty file. This script=20
>> causes about 10 MB memory leak. It can be observed by usage of=20
>> performance system monitor. This problems occurs in all available=20
>> enviroments: - IIS Webserver. - Apache webserver - PHP command line=20
>> interpreter Memory leak is observable only on Windows platform (tested o=
n=20
>> Windows XP). On Linux everything works OK. Does someone know how to solv=
e=20
>> this problem? Any help appreciated Best regards Melmack
>
> I've found exec to be flaky enough on windows that instead I use com to=
=20
> spawn the new process.
>
> $shell =3D new COM('WScript.Shell');
> $return =3D $shell->Run($cmd, 0, false);
> unset ($shell);
>
> Faster and no leaks ;) Only downside is you have to wrap cross-platform=
=20
> code with windows detection.=20

--=20
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


No virus found in this outgoing message.
Checked by AVG Free Edition.=20
Version: 7.5.485 / Virus Database: 269.13.12/997 - Release Date: 2007-09-09=
10:17
=20

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Memory leak occurs when exec() function is used on Windows platform

am 11.09.2007 17:07:45 von melmack3

""Melmack"" wrote in message
news:30.65.22994.08985E64@pb1.pair.com...
> Thank you for your reply.
> Unfortunately your method also causes memory leak.
> I have tested operating system and I have discovered
> that batch script listed below causes the same memory leak.
> That is why I think now that it is however not PHP fault but Windows bug.
>
> The Windows batch script contains:
> for /L %%i in (1,1,500) do cmd /C test.bat
>
> where test.bat is just an empty file.
>
> Maybe someone knows how to solve this problem?
>
> Best regards
> Melmack
>
>
After long hours of fighting and testing I have fixed the problem.
It was caused by an additional firewall installed on both computers
used by me for testing process. When I uninstalled it memory leak
disappeared.

Thanks all for help.
Best regards
Melmack

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Memory leak occurs when exec() function is used onWindows platform

am 12.09.2007 03:11:42 von leo.divinagraciaiii

hmmmm...

just tested it on my box: win xp sp2, apache 2.2.2, php 5.1.4 and 1gb of
ram. ran it under CLI.

copied your code and and created a 0 btye test.bat file.

rebooted the machine so a fresh start.

first time, i actually gained 3 megs of ram back, after the process
timed out after 60 seconds.

second time, after timing out, came back to same amount.


melmack wrote:
> Hi
>
> I have a big problem with shell commands execution via PHP.
> I have written a very short PHP script ilustrating the problem:
>
>
> >
>
> for($i=0;$i<1000;$i++)
> {
> exec("test.bat");
>
>
>
> }
>
>
> ?>
>
> test.bat is just an empty file.
>
>
> This script causes about 10 MB memory leak. It can be observed
> by usage of performance system monitor. This problems occurs in
> all available enviroments:
> - IIS Webserver.
> - Apache webserver
> - PHP command line interpreter
>
>
> Memory leak is observable only on Windows platform
> (tested on Windows XP). On Linux everything works OK.
>
>
> Does someone know how to solve this problem? Any help appreciated
>
>
> Best regards
> Melmack
>

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php