[PHP] Re: foreach and destroying variables for memory saving

2008-12-10 Thread Gal Gur-Arie
Tim | iHostNZ wrote:
 Hi All,
 
 Just to annoy the hell out of you, another thing that has been on my mind
 for a while:
 
 I love the foreach ($ar as $k = $v) { ... } construct and use it all the
 time. However, I read somewhere that foreach actually uses a copy of $ar
 instead of the array itself by reference. Wouldn't it be much more
 usefull/efficient, if foreach would use the array by reference? Then one
 could change arrays while iterating over them (without having to use the old
 fashioned for ($i=0; $icount($ar); $i++), also this doesnt work for
 associative arrays). I know you can do it with while and list somehow, but i
 personally find that language construct rather ugly and can never remember
 it. Is there another way that any of you use? Please enlighten me.
 I just use foreach because its easy, but it might not be the best. However,
 it seems to perform good enough for what i've done so far.
You can use:
$arr = array('abc'='123','ver'=phpversion());
foreach ($arr as $key=$val) {
echo $val.\n;
// Beware! - Changing $val will change it in $arr
}

// or like this:

$arr = array('abc'='123','ver'=phpversion());
reset($arr);
while (list($key, $val) = each($arr)) {
echo $val.\n;
}


 
 Somewhere i also read that one can save a lot of memory by destroying
 variables. Is that done with unset, setting it to null or something similar?
 So, i take there is no garbage collection in php? I've never actually looked
 at the c source code of php. Maybe its time to actually do that. But it
 might be easier if someone can answer this from the top of their head.
 
 Thanks for your patience.
 

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



[PHP] Re: how do i allow more than 2 threads of php to run?

2008-12-09 Thread Gal Gur-Arie
Rene Veerman wrote:
 i'm getting freezes for the 3rd to Nth concurrent request on my
 homeserver (got root, on debian4 + apache2).
 how can i allow more threads? like 50 or so?
 
 
Any chance that you're using session and checking it from the same
browser from different tabs (using same session ID)?

If the answer is yes. than you might want to look at the following
function: session_write_close()

http://www.php.net/manual/en/function.session-write-close.php


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



Re: [PHP] Using system

2003-09-17 Thread Gal Gur-Arie
Hello,

try this:
?php
$sMyHostname = exec('uname -a 21');
echo \n.$sMyHostname.\n;
?
Uros wrote:
Hello Robert,

I think not

here is my code

#!/usr/local/bin/php -q
?php
$ret = `nslookup -timeout=3 www.myhost.com |grep Non-existent host/domain`;
?
I always get automaticaly output. I also try to set implicit_flush to off,
use ob ob_...
nothing works.

best regards

Wednesday, September 17, 2003, 4:16:10 PM, you wrote:

RC Backtick style gets you the output...

RC $passwords = `cat /etc/passwd`;

RC Cheers,
RC Rob.
RC On Wed, 2003-09-17 at 09:55, esctoday.com | Wouter van Vliet wrote:

Don't think there's one function for it .. Though, you may want to try the
output buffers.
ob_start();
( .. Exec here ..)
$Var = ob_end_clean();
, 
Wouter

-Original Message-
From: Uros [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, September 17, 2003 3:18 PM
To: PHP General list
Subject: [PHP] Using system

Hello!

I'm pulling my hair. What is the right syntax to set output of some system
call to variable.
I tried everything (system, shell_exec,exec) and always get output to
screen.
Please help.

PHP version 4.3.3 CLI

--
Best regards,
Uros
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

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