Re: [PHP] Freeing Memory

2009-07-31 Thread Nisse Engström
On Fri, 31 Jul 2009 07:54:13 -0400, Dan Shirah wrote:

>>
>> How does that work considering that mysql_query() only
>> returns true or false on INSERT? I'd expect the script
>> to fail on $result not being a valid resource.
>>
> 
> I don't know about mysql as I work with MSSQL Server and Informix, but for
> me it works like this:
> 
>$insert = ifx_prepare("INSERT INTO my_table
>   VALUES ('0')", $connect_id);
>ifx_do($insert) or die ("Query failed");
>ifx_free_result($insert);
> 
> By using PREPARE and DO to execute the queries it allows ifx_free_result to
> release those resources.

That explains it. (You'd have to use the MySQLi extension
to use prepared statements with MySQL, unless I'm confused).
Personally, I try to make it a point to free resources as
soon as possible.


/Nisse

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



Re: [PHP] Freeing Memory

2009-07-31 Thread Dan Shirah
>
> How does that work considering that mysql_query() only
> returns true or false on INSERT? I'd expect the script
> to fail on $result not being a valid resource.
>

I don't know about mysql as I work with MSSQL Server and Informix, but for
me it works like this:

   $insert = ifx_prepare("INSERT INTO my_table
  VALUES ('0')", $connect_id);
   ifx_do($insert) or die ("Query failed");
   ifx_free_result($insert);

By using PREPARE and DO to execute the queries it allows ifx_free_result to
release those resources.


Re: [PHP] Freeing Memory

2009-07-31 Thread Nisse Engström
On Thu, 30 Jul 2009 10:42:26 -0400, Dan Shirah wrote:

> I don't know what version of SQL you are using, but I have found that using:
> 
> mysql_free_result($result);
> mssql_free_result($result);
> ifx_free_result($result);
> 
> Helped my queries run much faster and use less resources. I had something
> similar to your script where I would read lines from a huge file and then
> insert the contents into my database.  Before adding the above the process
> would take 20-30 minutes.  After freeing the results after each insert my
> script completed in about 5-8 minutes.

How does that work considering that mysql_query() only
returns true or false on INSERT? I'd expect the script
to fail on $result not being a valid resource.


/Nisse

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



Re: [PHP] Freeing Memory

2009-07-30 Thread Dan Shirah
>
> How  would you go about ensuring the memory is not exhausted when running a
> script ?
>
> I have a script, which to make it basic ... reads values from files, I
> create an array of values per file then with a foreach insert values into a
> table, I have added a line to echo the memory use after each array is done
> (after insert is done and the foreach is complete for the file) with: ->
> echo "Mem SQL: ".memory_get_usage() . "\n";
>
> It gave me this result below:
>
> Mem SQL: 8341312
> Mem SQL: 8461856
> Mem SQL: 8693440
> Mem SQL: 9327008
> Mem SQL: 9798952
> Mem SQL: 10238392
> Mem SQL: 10604776
>
> As can be seen the mem usage simply grows,
>
> I have added a line after each iteration of the foreach is complete to
> unset
> the vars and array ... thinking this would basically clear up the allocated
> memmory used by the array ... and it would start at 0 again for the next
> array looped, but obviously this is not quite the answer.
>
> The question is then how do you "clear"  memmory then ?
>

I don't know what version of SQL you are using, but I have found that using:

mysql_free_result($result);
mssql_free_result($result);
ifx_free_result($result);

Helped my queries run much faster and use less resources. I had something
similar to your script where I would read lines from a huge file and then
insert the contents into my database.  Before adding the above the process
would take 20-30 minutes.  After freeing the results after each insert my
script completed in about 5-8 minutes.

Just add that within your foreach loop after you execute your query that
inserts the info.

Hope that helps.

Dan


[PHP] Freeing Memory

2009-07-30 Thread Anton Heuschen
How  would you go about ensuring the memory is not exhausted when running a
script ?

I have a script, which to make it basic ... reads values from files, I
create an array of values per file then with a foreach insert values into a
table, I have added a line to echo the memory use after each array is done
(after insert is done and the foreach is complete for the file) with: ->
echo "Mem SQL: ".memory_get_usage() . "\n";

It gave me this result below:

Mem SQL: 8341312
Mem SQL: 8461856
Mem SQL: 8693440
Mem SQL: 9327008
Mem SQL: 9798952
Mem SQL: 10238392
Mem SQL: 10604776

As can be seen the mem usage simply grows,

I have added a line after each iteration of the foreach is complete to unset
the vars and array ... thinking this would basically clear up the allocated
memmory used by the array ... and it would start at 0 again for the next
array looped, but obviously this is not quite the answer.

The question is then how do you "clear"  memmory then ?


[PHP] Freeing memory for DOMDocument

2009-01-07 Thread Christoph Boget
I'm running through a large dataset and am generating/manipulating XML
documents for each record.  What's happening is that after a while, I
get a fatal error saying:

Fatal error: Allowed memory size of 167772160 bytes exhausted (tried
to allocate 32650313 bytes)

Each XML file I generate (an manipulate) can range from just a few
megs to upwards of 35 megs.  Judging from the error above, it looks
like the memory for the DOMDocument objects I instantiate is not
getting freed; it just continues to stay in memory until the memory is
completely exhausted.  The method (in my object) I am using to
instantiate a new DOMDocument is as follows:

protected function createCleanDomDocument()
{
/*
  if(( isset( $this->oDomXPath )) && ( !is_null( $this->oDomXPath )))
  {
unset( $this->oDomXPath );
  }

  if(( isset( $this->oDomDocument )) && ( !is_null( $this->oDomDocument )))
  {
unset( $this->oDomDocument );
  }
*/
  $this->oDomDocument = new DOMDocument( '1.0', 'iso-8859-1' );
  $this->oDomXPath= new DOMXpath( $this->oDomDocument );
}

which is used in both the constructor of my object and in a few other
places.  I would think that when the new DOMDocument is instantiated,
the memory used for the old value would get freed.  As you can see,
I've even tried to unset the variables but that doesn't seem to help
matters much, either.

Does anyone know how (or even if) I can explicitly free the memory
used for the DOMDocument?  Any help/advice would be greatly
appreciated!

thnx,
Christoph

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



[PHP] Freeing memory WAS emalloc() error being thrown {LONG} - MORE

2003-06-24 Thread Jay Blanchard
***pulling out what's left of my hair***

I have a situation where I open a new file, do a query, write to the
file, close the file, and then start over again at opening a new file
while looping through an array. As I do this I can watch memory
resources approach 0, ultimately failing the script before it gets
through the entore array. How do you free the memory after you close a
file without stopping the script? If I stop the script the memeory is
instantly freed up. I found the MySQL answers (mysql_free_result()), but
I also need to free memory after fclose(). Any ideas?

Thanks!

Jay

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