[PHP] Paging script

2009-09-30 Thread Angelo Zanetti

Hi All, 

I am looking for a paging script, not the normal type but slightly
different. It must show as follows: 

1 2 3 ... 12

Then: 

1 ... 678 ... 12

And 

1 ... 10 11 12

I have googled and not really found much and don't really want to reinvent
the wheel. I am sure I can write my own but due to time constraints ill like
to get a script that will assist me.

Thanks in advance
http://www.wapit.co.za
http://www.elemental.co.za



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



RE: [PHP] Paging script

2009-09-30 Thread Mert Oztekin
Sorry but I dont understand what you mean. Can you be more specific?

{1} 2 3 ... 12  (Startup / Total 12 pages)
When you click 7
1 ... 6 {7} 8 ... 12
When you click 11 or 12
1 ... 10 11 {12}

Do you mean something like this?


-Original Message-
From: Angelo Zanetti [mailto:ang...@elemental.co.za]
Sent: Wednesday, September 30, 2009 1:21 PM
To: php-general@lists.php.net
Subject: [PHP] Paging script


Hi All,

I am looking for a paging script, not the normal type but slightly
different. It must show as follows:

1 2 3 ... 12

Then:

1 ... 678 ... 12

And

1 ... 10 11 12

I have googled and not really found much and don't really want to reinvent
the wheel. I am sure I can write my own but due to time constraints ill like
to get a script that will assist me.

Thanks in advance
http://www.wapit.co.za
http://www.elemental.co.za



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


Bu mesaj ve ekleri, mesajda g?nderildi?i belirtilen ki?i/ki?ilere ?zeldir ve 
gizlidir. Size yanl??l?kla ula?m??sa l?tfen g?nderen kisiyi bilgilendiriniz ve 
mesaj? sisteminizden siliniz. Mesaj ve eklerinin i?eri?i ile ilgili olarak 
?irketimizin herhangi bir hukuki sorumlulu?u bulunmamaktad?r. ?irketimiz 
mesaj?n ve bilgilerinin size de?i?ikli?e u?rayarak veya ge? ula?mas?ndan, 
b?t?nl???n?n ve gizlili?inin korunamamas?ndan, vir?s i?ermesinden ve bilgisayar 
sisteminize verebilece?i herhangi bir zarardan sorumlu tutulamaz.

This message and attachments are confidential and intended for the 
individual(s) stated in this message. If you received this message in error, 
please immediately notify the sender and delete it from your system. Our 
company has no legal responsibility for the contents of the message and its 
attachments. Our company shall have no liability for any changes or late 
receiving, loss of integrity and confidentiality, viruses and any damages 
caused in anyway to your computer system.

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



RE: [PHP] Paging script

2009-09-30 Thread Angelo Zanetti


-Original Message-
From: Mert Oztekin [mailto:mozte...@anadolusigorta.com.tr] 
Sent: 30 September 2009 12:40 PM
To: 'Angelo Zanetti'; php-general@lists.php.net
Subject: RE: [PHP] Paging script 

Sorry but I dont understand what you mean. Can you be more specific?

{1} 2 3 ... 12  (Startup / Total 12 pages)
When you click 7
1 ... 6 {7} 8 ... 12
When you click 11 or 12
1 ... 10 11 {12}

Do you mean something like this?


Hi Mert, 

Yes I mean exactly like you have it there,

Regards
Angelo



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



RE: [PHP] Paging script

2009-09-30 Thread Ashley Sheridan
On Wed, 2009-09-30 at 12:59 +0200, Angelo Zanetti wrote:
 
 -Original Message-
 From: Mert Oztekin [mailto:mozte...@anadolusigorta.com.tr] 
 Sent: 30 September 2009 12:40 PM
 To: 'Angelo Zanetti'; php-general@lists.php.net
 Subject: RE: [PHP] Paging script 
 
 Sorry but I dont understand what you mean. Can you be more specific?
 
 {1} 2 3 ... 12  (Startup / Total 12 pages)
 When you click 7
 1 ... 6 {7} 8 ... 12
 When you click 11 or 12
 1 ... 10 11 {12}
 
 Do you mean something like this?
 
 
 Hi Mert, 
 
 Yes I mean exactly like you have it there,
 
 Regards
 Angelo
 
 
 

I'd just code it yourself, the logic behind it is pretty simple.

  * The numbers 1 and 12 (the total) will always display
  * The page you are on will display the number to either side of
it, unless that is 1 or 12 (the total)
  * If the page you are on is 2 or 11 (one less than the total) then
add in '...' on either side of the middle block.



Thanks,
Ash
http://www.ashleysheridan.co.uk




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



Re: [PHP] Paging script

2009-09-30 Thread Ruben Crespo
Hi all,

Maybe it is not just what you need but could be helpfull.

Here you have the code:

//---paginator.php
?php
function paginator ($current, $total, $per_page, $link, $limit) {

if ($current == '')
{
$current = 1;
}else{
$current = $current;
}

  $total_pages = ceil($total/$per_page);
  $previous = $current - 1;
  $next = $current + 1;


/*traduction*/
  $toFrom = pPage .$current. of .$total_pages./p;
  $Goto = Go to Page;
  $go = Go;


  $texto = 
  div id='paginacion'.$toFrom.
  ul;

  if ($current  1)
$texto .= lia href=\$link$previous\laquo;/a/li;
  else
$texto .= liblaquo;/b/li;


//Se lista hasta llegar a la posición actual
if ($current  $limit) {
$start = ($current - $limit) + 1;
$texto .= lib.../b/li;
} else {
$start = 1;
}

 for ($start; $start  $current; $start++) {
   $texto .= lia href=\$link$start\$start/a/li;
   }

//mostramos posicion actual
  $texto .= lib$current/b/li ;

//mostramos resto de registros
  for ($i=$current+1; $i=$total_pages; $i++) {

  if ($i  $limit)
  {
  $texto .= lib.../b/li;
  $i = $total_pages;
  }else{
  $texto .= lia href=\$link$i\$i/a/li ;
  }
}

  if ($current  $total_pages)
  {
  $texto .= lia href=\$link$next\raquo;/a/li;
  }else{
$texto .= libraquo;/b/li;
  }

 $texto .= /ul;


 //a form to go directly to the page you want
 $texto .= '!--FORMULARIO PAGINADOR--
div id=form_ir
form action='.$_SERVER[PHP_SELF].' method=get
fieldset
p'.$Goto.' input type=text size=3 name=page value= /
input type=submit name=ir value='.$go.' //p
/fieldset
/form
/div';



$texto .= 'br class=break /

/div
';

return $texto;

}

?
//---paginator.php

//---example.php
?php
include (paginator.php);

for ($n=0; $n=100; $n++)
{
$myArray [$n] = $n;
}

$total = count ($myArray); //the total elements in the array
$per_page = 5; //elements the script show
$link = example.php?page=; //link
$limit = 3; //number of items you show in the paginator list



if ($_GET[page])
{
$current = $_GET[page];
}else{
$current = $_POST[page];
}

$start = ($current-1) * $per_page;
$end = $start + $per_page;

//call to the paginator function ...
echo paginator ($current, $total, $per_page, $link, $limit);


//Show the results in different pages
for ($i = $start; $i=$end ;$i++)
{
echo $myArray[$i].br /;
}


?

//---example.php




2009/9/30 Angelo Zanetti ang...@elemental.co.za


 Hi All,

 I am looking for a paging script, not the normal type but slightly
 different. It must show as follows:

 1 2 3 ... 12

 Then:

 1 ... 678 ... 12

 And

 1 ... 10 11 12

 I have googled and not really found much and don't really want to reinvent
 the wheel. I am sure I can write my own but due to time constraints ill
 like
 to get a script that will assist me.

 Thanks in advance
 http://www.wapit.co.za
 http://www.elemental.co.za



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




-- 
http://peachep.wordpress.com


RE: [PHP] Paging script

2009-09-30 Thread Angelo Zanetti
 

 

  _  

From: Ruben Crespo [mailto:rumails...@gmail.com] 
Sent: 30 September 2009 01:23 PM
To: Angelo Zanetti
Cc: php-general@lists.php.net
Subject: Re: [PHP] Paging script

 

Hi all,

Maybe it is not just what you need but could be helpfull.

Here you have the code:

//---paginator.php--
--
?php
function paginator ($current, $total, $per_page, $link, $limit) {

if ($current == '')
{
$current = 1;
}else{
$current = $current;
}

  $total_pages = ceil($total/$per_page);
  $previous = $current - 1;
  $next = $current + 1;
  

/*traduction*/
  $toFrom = pPage .$current. of .$total_pages./p;
  $Goto = Go to Page;
  $go = Go;
 

  $texto = 
  div id='paginacion'.$toFrom.
  ul;
  
  if ($current  1)
$texto .= lia href=\$link$previous\laquo;/a/li;
  else
$texto .= liblaquo;/b/li;
  
  
//Se lista hasta llegar a la posición actual  
if ($current  $limit) {
$start = ($current - $limit) + 1;
$texto .= lib.../b/li;
} else {
$start = 1;
}
   
 for ($start; $start  $current; $start++) {
   $texto .= lia href=\$link$start\$start/a/li;
   }
  
//mostramos posicion actual
  $texto .= lib$current/b/li ;
 
//mostramos resto de registros
  for ($i=$current+1; $i=$total_pages; $i++) {
  
  if ($i  $limit)
  {
  $texto .= lib.../b/li;
  $i = $total_pages;
  }else{
  $texto .= lia href=\$link$i\$i/a/li ;
  }
}
 
  if ($current  $total_pages)
  {
  $texto .= lia href=\$link$next\raquo;/a/li;
  }else{
$texto .= libraquo;/b/li;
  }
  
 $texto .= /ul; 
 
 
 //a form to go directly to the page you want 
 $texto .= '!--FORMULARIO PAGINADOR--
div id=form_ir
form action='.$_SERVER[PHP_SELF].' method=get
fieldset
p'.$Goto.' input type=text size=3 name=page value= /
input type=submit name=ir value='.$go.' //p
/fieldset
/form
/div';



$texto .= 'br class=break /

/div
';
  
return $texto;

}

?
//---paginator.php--
--

//---example.php

?php
include (paginator.php);

for ($n=0; $n=100; $n++)
{
$myArray [$n] = $n;
}

$total = count ($myArray); //the total elements in the array
$per_page = 5; //elements the script show
$link = example.php?page=; //link
$limit = 3; //number of items you show in the paginator list



if ($_GET[page])
{
$current = $_GET[page];
}else{
$current = $_POST[page];
}

$start = ($current-1) * $per_page;
$end = $start + $per_page;

//call to the paginator function ...
echo paginator ($current, $total, $per_page, $link, $limit);


//Show the results in different pages
for ($i = $start; $i=$end ;$i++)
{
echo $myArray[$i].br /;
}


?

//---example.php



Thanks ruben very much :-)

 

Regards

Angelo

 

http://www.wapit.co.za
http://www.elemental.co.za



RE: [PHP] Paging script

2009-09-30 Thread Mert Oztekin
This should do it. i didnt have time to test so there may be some bugs.


function pageit($limit , $total, $page, $link)
{
$last = intval($total / $limit) + ($total % $limit ==0 ? 0:1);
if(!is_numeric($page) || $page  $last)
$page = 1;

$pages[] = 1;

if($page == 1)
{
$pages[] = 2;
$pages[] = 3;
}
else
if($page == $last)
{
$pages[]= $last - 2;
$pages[] = $last -1;
}
else
{
if($page - 1  1)
$pages[] = $page -1;
$pages[] = $page;
if($page +1  $last)
$pages[] = $page +1;

}

$pages[] = $last;

for($i=0; $i  count($pages) ; $i++)
{
if($pages[$i] 1 || $pages[$i]  $last)
continue;
if($i0)
if($pages[$i] - $pages[$i-1]  1 )
echo '...';
echo 'a href=' . $link . '?page=' . $pages[$i]. '' . 
$pages[$i] . '/a';
}
}




-Original Message-
From: Angelo Zanetti [mailto:ang...@elemental.co.za]
Sent: Wednesday, September 30, 2009 1:59 PM
To: Mert Oztekin; php-general@lists.php.net
Subject: RE: [PHP] Paging script



-Original Message-
From: Mert Oztekin [mailto:mozte...@anadolusigorta.com.tr]
Sent: 30 September 2009 12:40 PM
To: 'Angelo Zanetti'; php-general@lists.php.net
Subject: RE: [PHP] Paging script

Sorry but I dont understand what you mean. Can you be more specific?

{1} 2 3 ... 12  (Startup / Total 12 pages)
When you click 7
1 ... 6 {7} 8 ... 12
When you click 11 or 12
1 ... 10 11 {12}

Do you mean something like this?


Hi Mert,

Yes I mean exactly like you have it there,

Regards
Angelo



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


Bu mesaj ve ekleri, mesajda g?nderildi?i belirtilen ki?i/ki?ilere ?zeldir ve 
gizlidir. Size yanl??l?kla ula?m??sa l?tfen g?nderen kisiyi bilgilendiriniz ve 
mesaj? sisteminizden siliniz. Mesaj ve eklerinin i?eri?i ile ilgili olarak 
?irketimizin herhangi bir hukuki sorumlulu?u bulunmamaktad?r. ?irketimiz 
mesaj?n ve bilgilerinin size de?i?ikli?e u?rayarak veya ge? ula?mas?ndan, 
b?t?nl???n?n ve gizlili?inin korunamamas?ndan, vir?s i?ermesinden ve bilgisayar 
sisteminize verebilece?i herhangi bir zarardan sorumlu tutulamaz.

This message and attachments are confidential and intended for the 
individual(s) stated in this message. If you received this message in error, 
please immediately notify the sender and delete it from your system. Our 
company has no legal responsibility for the contents of the message and its 
attachments. Our company shall have no liability for any changes or late 
receiving, loss of integrity and confidentiality, viruses and any damages 
caused in anyway to your computer system.

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



Re: [PHP] Paging script

2009-09-30 Thread Ruben Crespo
O.K Angelo,

I wish you that you find the code useful for your projects.

Best Regards !!

Rubén Crespo

2009/9/30 Angelo Zanetti ang...@elemental.co.za





  _

 From: Ruben Crespo [mailto:rumails...@gmail.com]
 Sent: 30 September 2009 01:23 PM
 To: Angelo Zanetti
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] Paging script



 Hi all,

 Maybe it is not just what you need but could be helpfull.

 Here you have the code:


 //---paginator.php--
 --
 ?php
 function paginator ($current, $total, $per_page, $link, $limit) {

if ($current == '')
{
$current = 1;
}else{
$current = $current;
}

  $total_pages = ceil($total/$per_page);
  $previous = $current - 1;
  $next = $current + 1;


 /*traduction*/
  $toFrom = pPage .$current. of .$total_pages./p;
  $Goto = Go to Page;
  $go = Go;


  $texto = 
  div id='paginacion'.$toFrom.
  ul;

  if ($current  1)
$texto .= lia href=\$link$previous\laquo;/a/li;
  else
$texto .= liblaquo;/b/li;


 //Se lista hasta llegar a la posición actual
if ($current  $limit) {
$start = ($current - $limit) + 1;
$texto .= lib.../b/li;
} else {
$start = 1;
}

 for ($start; $start  $current; $start++) {
   $texto .= lia href=\$link$start\$start/a/li;
   }

 //mostramos posicion actual
  $texto .= lib$current/b/li ;

 //mostramos resto de registros
  for ($i=$current+1; $i=$total_pages; $i++) {

  if ($i  $limit)
  {
  $texto .= lib.../b/li;
  $i = $total_pages;
  }else{
  $texto .= lia href=\$link$i\$i/a/li ;
  }
}

  if ($current  $total_pages)
  {
  $texto .= lia href=\$link$next\raquo;/a/li;
  }else{
$texto .= libraquo;/b/li;
  }

  $texto .= /ul;


  //a form to go directly to the page you want
  $texto .= '!--FORMULARIO PAGINADOR--
 div id=form_ir
form action='.$_SERVER[PHP_SELF].' method=get
fieldset
p'.$Goto.' input type=text size=3 name=page value= /
input type=submit name=ir value='.$go.' //p
/fieldset
/form
 /div';



 $texto .= 'br class=break /

 /div
 ';

 return $texto;

 }

 ?

 //---paginator.php--
 --


 //---example.php
 
 ?php
 include (paginator.php);

 for ($n=0; $n=100; $n++)
 {
 $myArray [$n] = $n;
 }

 $total = count ($myArray); //the total elements in the array
 $per_page = 5; //elements the script show
 $link = example.php?page=; //link
 $limit = 3; //number of items you show in the paginator list



 if ($_GET[page])
 {
 $current = $_GET[page];
 }else{
 $current = $_POST[page];
 }

 $start = ($current-1) * $per_page;
 $end = $start + $per_page;

 //call to the paginator function ...
 echo paginator ($current, $total, $per_page, $link, $limit);


 //Show the results in different pages
 for ($i = $start; $i=$end ;$i++)
 {
 echo $myArray[$i].br /;
 }


 ?


 //---example.php
 


 Thanks ruben very much :-)



 Regards

 Angelo



 http://www.wapit.co.za
 http://www.elemental.co.za




-- 
http://peachep.wordpress.com


Re: [PHP] Where's my memory going?!

2009-09-30 Thread Philip Thompson

On Sep 29, 2009, at 5:51 PM, Jim Lucas wrote:


Philip Thompson wrote:

On Sep 29, 2009, at 4:38 PM, Jim Lucas wrote:


Philip Thompson wrote:

On Sep 28, 2009, at 4:40 PM, jeff brown wrote:

Yes, that's the best way to clean up after yourself.  And you  
really

should use that on anything you have sitting around daemon like.

Jeff

Philip Thompson wrote:

On Sep 28, 2009, at 4:27 PM, Ralph Deffke wrote:
well this sound clearly to me like you are not freeing  
resultsets
you are not going to use anymore. In long scripts you have to  
take

care of this. on short scripts you can be a bit weak on that,
because the resultsets are closed and freed on script ending.

assumed u r using MySQL are u using mysql_free_result($result)

goog luck

ralph_def...@yahoo.de


Philip Thompson philthath...@gmail.com wrote in message
news:9c0b9c4c-5e64-4519-862b-8a3e1da4d...@gmail.com...

Hi all.

I have a script that opens a socket, creates a persistent mysql
connection, and loops to receive data. When the amount of  
specified
data has been received, it calls a class which processes the  
data

and
inserts it into the database. Each iteration, I unset/ 
destruct that

class I call. However, the script keeps going up in memory and
eventually runs out, causing a fatal error. Any thoughts on  
where to

start to see where I'm losing my memory?

Thanks in advance,
~Philip
I am not using mysql_free_result(). Is that highly recommended  
by all?

Thanks,
~Philip


I took your suggestions and made sure to clean up after myself. I'm
running into something that *appears* to be a bug with
mysql_free_result(). Here's a snippet of my db class.

?php
class db {
  function fetch ($sql, $assoc=false)
  {
  echo \nMemory usage before query:  . number_format
(memory_get_usage ()) . \n;
  $resultSet = $this-query($sql);
  echo Memory usage after  query:  . number_format
(memory_get_usage ()) . \n;

  if (!$assoc) { $result = $this-fetch_row($resultSet); }
  else {
  $result = $this-fetch_array($resultSet);
  echo Memory usage after  fetch:  . number_format
(memory_get_usage ()) . \n;
  }

  $this-freeResult($resultSet);
  echo Memory usage after   free:  . number_format
(memory_get_usage ()) . \n;

  return $result;
  }

  function freeResult ($result)
  {
  if (is_resource ($result)) {
  if (!mysql_free_result ($result)) { echo Memory could  
not

be freed\n; }
  }
  unset ($result); // For good measure
  }

  function fetch_row ($set) {
  return mysql_fetch_row ($set);
  }

  function fetch_array ($set) {
  return mysql_fetch_array ($set, MYSQL_ASSOC);
  }
}

// I seem to be losing memory when I call this
$db-fetch($sql);
?

The result I get with this is...

Memory usage before query: 6,406,548
Memory usage after  query: 6,406,548
Memory usage after  fetch: 6,406,548
Memory usage after   free: 6,406,572

As you may notice, the memory actually goes UP after the  
*freeing* of
memory. Why is this happening?! What have I done wrong? Is this a  
bug?

Any thoughts would be appreciated.



First off, my question would be, is your query actually working?
Because I
would imagine that if you were getting results back from the DB,  
that

the amount
of memory being used would increase between step 1  2.

Check to make sure that you are getting results.


I'm confident the queries are working (there's many of them and I  
know

the data they're returning is correct), but they may not always be
returning results. The memory value does change in some instances...

Memory usage before query: 5,138,372
Memory usage after  query: 5,138,396
Memory usage after   free: 5,138,556

This was one that use fetch_row() instead of fetch_array(), but the  
same

difference. I did some searching around and I think it's a bug in PHP
and/or Zend Memory Management engine. As I mentioned in a previous  
post
about mysql_query() not allocating memory appropriately, I believe  
this

could quite possibly be the case. Several people have reported bugs
similar to this... unfortunately, they are marked as (erroneously?)
bogus or said it has been fixed (when, IMO, it has not).

http://bugs.php.net/bug.php?id=40883
http://bugs.php.net/bug.php?id=28424
http://bugs.php.net/bug.php?id=41871

I'm using version 5.2.6 on Fedora 8 and the bug still appears to be
there. I think I'm going to take a different approach to fix this.  
I'll
create a shell script to loop and invoke the socket listener  
script, and

when it gathers data, call the import script. This way, the php
script(s) will end execution after each iteration and release the
memory. Is this reasonable?

This has been a long day. Thanks for your input. Any more thoughts  
are

welcome.

~Philip



Doesn't PHP only give back a pointer back from MySQL when it runs  
a query?
Then what PHP does is uses that pointer to mysql to request the  
next row of

results?

Couldn't you use the unbuffered-query function for this?


Re: [PHP] Where's my memory going?!

2009-09-30 Thread Philip Thompson

On Sep 29, 2009, at 6:15 PM, Eddie Drapkin wrote:


On Tue, Sep 29, 2009 at 6:51 PM, Jim Lucas li...@cmsws.com wrote:

Philip Thompson wrote:

On Sep 29, 2009, at 4:38 PM, Jim Lucas wrote:


Philip Thompson wrote:

On Sep 28, 2009, at 4:40 PM, jeff brown wrote:

Yes, that's the best way to clean up after yourself.  And you  
really

should use that on anything you have sitting around daemon like.

Jeff

Philip Thompson wrote:

On Sep 28, 2009, at 4:27 PM, Ralph Deffke wrote:
well this sound clearly to me like you are not freeing  
resultsets
you are not going to use anymore. In long scripts you have to  
take

care of this. on short scripts you can be a bit weak on that,
because the resultsets are closed and freed on script ending.

assumed u r using MySQL are u using mysql_free_result($result)

goog luck

ralph_def...@yahoo.de


Philip Thompson philthath...@gmail.com wrote in message
news:9c0b9c4c-5e64-4519-862b-8a3e1da4d...@gmail.com...

Hi all.

I have a script that opens a socket, creates a persistent  
mysql
connection, and loops to receive data. When the amount of  
specified
data has been received, it calls a class which processes the  
data

and
inserts it into the database. Each iteration, I unset/ 
destruct that

class I call. However, the script keeps going up in memory and
eventually runs out, causing a fatal error. Any thoughts on  
where to

start to see where I'm losing my memory?

Thanks in advance,
~Philip
I am not using mysql_free_result(). Is that highly recommended  
by all?

Thanks,
~Philip


I took your suggestions and made sure to clean up after myself.  
I'm

running into something that *appears* to be a bug with
mysql_free_result(). Here's a snippet of my db class.

?php
class db {
   function fetch ($sql, $assoc=false)
   {
   echo \nMemory usage before query:  . number_format
(memory_get_usage ()) . \n;
   $resultSet = $this-query($sql);
   echo Memory usage after  query:  . number_format
(memory_get_usage ()) . \n;

   if (!$assoc) { $result = $this-fetch_row($resultSet); }
   else {
   $result = $this-fetch_array($resultSet);
   echo Memory usage after  fetch:  . number_format
(memory_get_usage ()) . \n;
   }

   $this-freeResult($resultSet);
   echo Memory usage after   free:  . number_format
(memory_get_usage ()) . \n;

   return $result;
   }

   function freeResult ($result)
   {
   if (is_resource ($result)) {
   if (!mysql_free_result ($result)) { echo Memory  
could not

be freed\n; }
   }
   unset ($result); // For good measure
   }

   function fetch_row ($set) {
   return mysql_fetch_row ($set);
   }

   function fetch_array ($set) {
   return mysql_fetch_array ($set, MYSQL_ASSOC);
   }
}

// I seem to be losing memory when I call this
$db-fetch($sql);
?

The result I get with this is...

Memory usage before query: 6,406,548
Memory usage after  query: 6,406,548
Memory usage after  fetch: 6,406,548
Memory usage after   free: 6,406,572

As you may notice, the memory actually goes UP after the  
*freeing* of
memory. Why is this happening?! What have I done wrong? Is this  
a bug?

Any thoughts would be appreciated.



First off, my question would be, is your query actually working?
Because I
would imagine that if you were getting results back from the DB,  
that

the amount
of memory being used would increase between step 1  2.

Check to make sure that you are getting results.


I'm confident the queries are working (there's many of them and I  
know

the data they're returning is correct), but they may not always be
returning results. The memory value does change in some instances...

Memory usage before query: 5,138,372
Memory usage after  query: 5,138,396
Memory usage after   free: 5,138,556

This was one that use fetch_row() instead of fetch_array(), but  
the same
difference. I did some searching around and I think it's a bug in  
PHP
and/or Zend Memory Management engine. As I mentioned in a previous  
post
about mysql_query() not allocating memory appropriately, I believe  
this

could quite possibly be the case. Several people have reported bugs
similar to this... unfortunately, they are marked as (erroneously?)
bogus or said it has been fixed (when, IMO, it has not).

http://bugs.php.net/bug.php?id=40883
http://bugs.php.net/bug.php?id=28424
http://bugs.php.net/bug.php?id=41871

I'm using version 5.2.6 on Fedora 8 and the bug still appears to be
there. I think I'm going to take a different approach to fix this.  
I'll
create a shell script to loop and invoke the socket listener  
script, and

when it gathers data, call the import script. This way, the php
script(s) will end execution after each iteration and release the
memory. Is this reasonable?

This has been a long day. Thanks for your input. Any more thoughts  
are

welcome.

~Philip



Doesn't PHP only give back a pointer back from MySQL when it runs  
a query?
Then what PHP does is uses that pointer to mysql to request the  

Re: [PHP] Where's my memory going?!

2009-09-30 Thread Ralph Deffke
Hi Philip,

before u start running arround and taking ur hand on major changes I would
like u to concider the following:

the way u use the memory_get_usage() is incomplete use the function like
memory_get_usage( true ) if this is set the REAL SIZE OF MEMORY ALLOCATED
FROM THE SYSTEM is shown.

some posters gave u little winks, like has the garbage collection been run?

freeing the results is important, it means the memory is available for other
data, but it does not necesarily mean it is reported just a step later as
free! u are running on concurrent os.

the only way u can test that is in real world. clean the whole application
with the free_result_set and see the effect.

I'm personaly not shure if the memory allocated for result sets for MySQL
are reported as used by PHP anyway. It might be that the amount of memory is
not shown as PHP used even if u set real_usage = true. it is something to
test.

I think the way u tested the effect of freeing the results is just wrong.

hope that helps

ralph_def...@yahoo.de



u came up with the problem that ur server is running out of memory.
Philip Thompson philthath...@gmail.com wrote in message
news:098d2158-9199-4983-aec4-6ffb06c1c...@gmail.com...
 On Sep 29, 2009, at 6:15 PM, Eddie Drapkin wrote:

  On Tue, Sep 29, 2009 at 6:51 PM, Jim Lucas li...@cmsws.com wrote:
  Philip Thompson wrote:
  On Sep 29, 2009, at 4:38 PM, Jim Lucas wrote:
 
  Philip Thompson wrote:
  On Sep 28, 2009, at 4:40 PM, jeff brown wrote:
 
  Yes, that's the best way to clean up after yourself.  And you
  really
  should use that on anything you have sitting around daemon like.
 
  Jeff
 
  Philip Thompson wrote:
  On Sep 28, 2009, at 4:27 PM, Ralph Deffke wrote:
  well this sound clearly to me like you are not freeing
  resultsets
  you are not going to use anymore. In long scripts you have to
  take
  care of this. on short scripts you can be a bit weak on that,
  because the resultsets are closed and freed on script ending.
 
  assumed u r using MySQL are u using mysql_free_result($result)
 
  goog luck
 
  ralph_def...@yahoo.de
 
 
  Philip Thompson philthath...@gmail.com wrote in message
  news:9c0b9c4c-5e64-4519-862b-8a3e1da4d...@gmail.com...
  Hi all.
 
  I have a script that opens a socket, creates a persistent
  mysql
  connection, and loops to receive data. When the amount of
  specified
  data has been received, it calls a class which processes the
  data
  and
  inserts it into the database. Each iteration, I unset/
  destruct that
  class I call. However, the script keeps going up in memory and
  eventually runs out, causing a fatal error. Any thoughts on
  where to
  start to see where I'm losing my memory?
 
  Thanks in advance,
  ~Philip
  I am not using mysql_free_result(). Is that highly recommended
  by all?
  Thanks,
  ~Philip
 
  I took your suggestions and made sure to clean up after myself.
  I'm
  running into something that *appears* to be a bug with
  mysql_free_result(). Here's a snippet of my db class.
 
  ?php
  class db {
 function fetch ($sql, $assoc=false)
 {
 echo \nMemory usage before query:  . number_format
  (memory_get_usage ()) . \n;
 $resultSet = $this-query($sql);
 echo Memory usage after  query:  . number_format
  (memory_get_usage ()) . \n;
 
 if (!$assoc) { $result = $this-fetch_row($resultSet); }
 else {
 $result = $this-fetch_array($resultSet);
 echo Memory usage after  fetch:  . number_format
  (memory_get_usage ()) . \n;
 }
 
 $this-freeResult($resultSet);
 echo Memory usage after   free:  . number_format
  (memory_get_usage ()) . \n;
 
 return $result;
 }
 
 function freeResult ($result)
 {
 if (is_resource ($result)) {
 if (!mysql_free_result ($result)) { echo Memory
  could not
  be freed\n; }
 }
 unset ($result); // For good measure
 }
 
 function fetch_row ($set) {
 return mysql_fetch_row ($set);
 }
 
 function fetch_array ($set) {
 return mysql_fetch_array ($set, MYSQL_ASSOC);
 }
  }
 
  // I seem to be losing memory when I call this
  $db-fetch($sql);
  ?
 
  The result I get with this is...
 
  Memory usage before query: 6,406,548
  Memory usage after  query: 6,406,548
  Memory usage after  fetch: 6,406,548
  Memory usage after   free: 6,406,572
 
  As you may notice, the memory actually goes UP after the
  *freeing* of
  memory. Why is this happening?! What have I done wrong? Is this
  a bug?
  Any thoughts would be appreciated.
 
 
  First off, my question would be, is your query actually working?
  Because I
  would imagine that if you were getting results back from the DB,
  that
  the amount
  of memory being used would increase between step 1  2.
 
  Check to make sure that you are getting results.
 
  I'm confident the queries are working (there's many of them and I
  know
  the data they're returning is correct), but they may not always be
  

[PHP] Converting print_r() output to an array

2009-09-30 Thread James Colannino
Hey everyone, I was pretty sure there was an easy built-in solution for
what I want to do, but I've been googling around with no luck.
Basically, I just want to take a string containing the output of
print_r() and convert it back into an array again.

That is possible, right?  If so, how do I go about it?  If not, what's a
quick and easy way to parse a string and turn it into an array (I don't
necessarily need the string to be in the format print_r returns).

Thanks!

James

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



Re: [PHP] Converting print_r() output to an array

2009-09-30 Thread Michael Shadle
first off, if you pass print_r($var, true) it will return it instead
of printing it. if you go that route.

have you looked at var_export() ?

On Wed, Sep 30, 2009 at 8:07 PM, James Colannino ja...@colannino.org wrote:
 Hey everyone, I was pretty sure there was an easy built-in solution for
 what I want to do, but I've been googling around with no luck.
 Basically, I just want to take a string containing the output of
 print_r() and convert it back into an array again.

 That is possible, right?  If so, how do I go about it?  If not, what's a
 quick and easy way to parse a string and turn it into an array (I don't
 necessarily need the string to be in the format print_r returns).

 Thanks!

 James

 --
 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



Re: [PHP] Converting print_r() output to an array

2009-09-30 Thread Jonathan Tapicer
Hi,

May be you want to take a look at serialize and unserialize functions,
serialize generates a string from a variable and then unserialize can
give you the value of the variable back from the string.

Regards,

Jonathan


On Thu, Oct 1, 2009 at 12:07 AM, James Colannino ja...@colannino.org wrote:
 Hey everyone, I was pretty sure there was an easy built-in solution for
 what I want to do, but I've been googling around with no luck.
 Basically, I just want to take a string containing the output of
 print_r() and convert it back into an array again.

 That is possible, right?  If so, how do I go about it?  If not, what's a
 quick and easy way to parse a string and turn it into an array (I don't
 necessarily need the string to be in the format print_r returns).

 Thanks!

 James

 --
 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



Re: [PHP] Converting print_r() output to an array

2009-09-30 Thread Daniel Brown
On Wed, Sep 30, 2009 at 23:07, James Colannino ja...@colannino.org wrote:
 Hey everyone, I was pretty sure there was an easy built-in solution for
 what I want to do, but I've been googling around with no luck.
 Basically, I just want to take a string containing the output of
 print_r() and convert it back into an array again.

Well, print_r() simply iterates the array and prints it so if
you just want the array, skip print_r() entirely and use the variable
you were passing to it.

 That is possible, right?  If so, how do I go about it?  If not, what's a
 quick and easy way to parse a string and turn it into an array (I don't
 necessarily need the string to be in the format print_r returns).

There's plenty of ways to parse strings into arrays, it just
depends on how you want to do it.  For one example, if you wanted to
split each word into an individual array value, you could do:

?php
$sentence = This is a test.;
$words = explode(' ',$sentence);
/*
Then $words would contain:
[0] = This
[1] = is
[2] = a
[3] = test.
*/
?

Then, say you wanted to shuffle the words around, and then convert
them back to an array.  I don't know why, just say it out loud.
I'll wait.

Nevermind, here's the example anyway:

?php
// From $words in the previous example
shuffle($words);
$sentence = implode(' ',$words);
?

The latter example will mix up the words and put them back into a
sentence, with a whitespace (' ') as the glue between them.

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

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



[PHP] POST without POSTing

2009-09-30 Thread Paul M Foster
I'm sure this has been covered before, but I'm not even sure how to
search in the archives for it.

I have a form that collects certain info via POST. It is re-entrant, so
when the user hits the submit button, it checks the input and does
whatever sanity checks it needs to. If all is okay, it must now pass
some of that info to another URL (offsite) via POST. Normally, the
information would be passed via a series of GET variables or SESSION
variables. But in this case the site the user is being directed to must
receive the information via POST.

I'm not sure how to do this. Please no exotic external libraries my
shared hosting provider doesn't include. RTFM will be fine; just tell me
which Fine Manual to Read.

Paul

-- 
Paul M. Foster

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



Re: [PHP] POST without POSTing

2009-09-30 Thread Daniel Brown
On Wed, Sep 30, 2009 at 23:29, Paul M Foster pa...@quillandmouse.com wrote:

 I'm not sure how to do this. Please no exotic external libraries my
 shared hosting provider doesn't include. RTFM will be fine; just tell me
 which Fine Manual to Read.

Nothing too exotic at all, Paul.  Check out cURL:

http://php.net/curl

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

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



Re: [PHP] POST without POSTing

2009-09-30 Thread Paul M Foster
On Wed, Sep 30, 2009 at 11:36:55PM -0400, Daniel Brown wrote:

 On Wed, Sep 30, 2009 at 23:29, Paul M Foster pa...@quillandmouse.com wrote:
 
  I'm not sure how to do this. Please no exotic external libraries my
  shared hosting provider doesn't include. RTFM will be fine; just tell me
  which Fine Manual to Read.
 
 Nothing too exotic at all, Paul.  Check out cURL:
 
 http://php.net/curl

I was afraid you were going to say that, and I wasn't sure cURL was
supported on that server. But I just loaded phpinfo on that server, and
it is supported.

However, assuming it *wasn't*, I've found the following example from a
google search (thank goodness for google's hinting or I couldn't have
found it):

$fp = fsockopen(www.site.com, 80);
fputs($fp, POST /script.php HTTP/1.0
Host: www.site.com
Content-Length: 7

q=proxy);

I don't know much about doing things this way. It appears that when done
this way, the body must be separated by a newline, just like email.
And it appears that the content-length of 7 indicates the length of the
q=proxy string. Assuming I piled on a few other passed variables the
same way as q, separated by newlines (and adjusted the Content-Length
accordingly), would the above work? Are there liabilities to doing it
this way?

Paul

-- 
Paul M. Foster

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



Re: [PHP] POST without POSTing

2009-09-30 Thread Daniel Brown
On Thu, Oct 1, 2009 at 00:16, Paul M Foster pa...@quillandmouse.com wrote:

 However, assuming it *wasn't*, I've found the following example from a
 google search (thank goodness for google's hinting or I couldn't have
 found it):

 $fp = fsockopen(www.site.com, 80);
 fputs($fp, POST /script.php HTTP/1.0
 Host: www.site.com
 Content-Length: 7

 q=proxy);

 I don't know much about doing things this way. It appears that when done
 this way, the body must be separated by a newline, just like email.
 And it appears that the content-length of 7 indicates the length of the
 q=proxy string. Assuming I piled on a few other passed variables the
 same way as q, separated by newlines (and adjusted the Content-Length
 accordingly), would the above work? Are there liabilities to doing it
 this way?

Yes.  Hosts are more likely to have cURL installed and available
than fsockopen() or URL-based fopen() calls, so portability is greater
with cURL.  It's also a bit faster.  Still, as you know, there's
always more than one way to skin a cute, furry, delicious little
kitten.

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

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



Re: [PHP] POST without POSTing

2009-09-30 Thread Lars Torben Wilson
On Thu, 1 Oct 2009 00:16:27 -0400
Paul M Foster pa...@quillandmouse.com wrote:

 On Wed, Sep 30, 2009 at 11:36:55PM -0400, Daniel Brown wrote:
 
  On Wed, Sep 30, 2009 at 23:29, Paul M Foster
  pa...@quillandmouse.com wrote:
  
   I'm not sure how to do this. Please no exotic external libraries
   my shared hosting provider doesn't include. RTFM will be fine;
   just tell me which Fine Manual to Read.
  
  Nothing too exotic at all, Paul.  Check out cURL:
  
  http://php.net/curl
 
 I was afraid you were going to say that, and I wasn't sure cURL was
 supported on that server. But I just loaded phpinfo on that server,
 and it is supported.
 
 However, assuming it *wasn't*, I've found the following example from a
 google search (thank goodness for google's hinting or I couldn't
 have found it):
 
 $fp = fsockopen(www.site.com, 80);
 fputs($fp, POST /script.php HTTP/1.0
 Host: www.site.com
 Content-Length: 7
 
 q=proxy);
 
 I don't know much about doing things this way. It appears that when
 done this way, the body must be separated by a newline, just like
 email. And it appears that the content-length of 7 indicates the
 length of the q=proxy string. Assuming I piled on a few other
 passed variables the same way as q, separated by newlines (and
 adjusted the Content-Length accordingly), would the above work? Are
 there liabilities to doing it this way?
 
 Paul
 

Not separated by newlines; separated by ampersands. But otherwise,
that's just raw HTTP 1.1 protocol. cURL and other tools might look a bit
more complicated at first, but (assuming they're available) they do
shield you from the raw protocol a bit. No real liability to doing it
that way other than it's a bit more work.

http://developers.sun.com/mobility/midp/ttips/HTTPPost/


Regards,

Torben

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



Re: [PHP] POST without POSTing

2009-09-30 Thread Paul M Foster
On Thu, Oct 01, 2009 at 12:24:41AM -0400, Daniel Brown wrote:

 On Thu, Oct 1, 2009 at 00:16, Paul M Foster pa...@quillandmouse.com wrote:
 
  However, assuming it *wasn't*, I've found the following example from a
  google search (thank goodness for google's hinting or I couldn't have
  found it):
 
  $fp = fsockopen(www.site.com, 80);
  fputs($fp, POST /script.php HTTP/1.0
  Host: www.site.com
  Content-Length: 7
 
  q=proxy);
 
  I don't know much about doing things this way. It appears that when done
  this way, the body must be separated by a newline, just like email.
  And it appears that the content-length of 7 indicates the length of the
  q=proxy string. Assuming I piled on a few other passed variables the
  same way as q, separated by newlines (and adjusted the Content-Length
  accordingly), would the above work? Are there liabilities to doing it
  this way?
 
 Yes.  Hosts are more likely to have cURL installed and available
 than fsockopen() or URL-based fopen() calls, so portability is greater
 with cURL.  It's also a bit faster.  Still, as you know, there's
 always more than one way to skin a cute, furry, delicious little
 kitten.

fsockopen() appears to be part of the standard network functions in PHP,
like the header() function. Do you mean that many hosts support the
function (as part of PHP) but don't support its use with external hosts?
Is there a way to determine this support from looking at phpinfo()?

Paul

-- 
Paul M. Foster

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



Re: [PHP] POST without POSTing

2009-09-30 Thread Daniel Brown
On Thu, Oct 1, 2009 at 00:41, Paul M Foster pa...@quillandmouse.com wrote:

 fsockopen() appears to be part of the standard network functions in PHP,
 like the header() function. Do you mean that many hosts support the
 function (as part of PHP) but don't support its use with external hosts?
 Is there a way to determine this support from looking at phpinfo()?

fsockopen() is a socket function, as the name suggests.  Hosts can
disable the usage of sockets.  In fact, check Google and you'll see
several folks complaining of their host having it disabled.

As for fopen(), there's a php.ini value `allow_url_fopen` that a
lot of hosts have set to 'no,' I'm sure with the intent to increase
security but when you can still use cURL and exec('wget'), it kind
of defeats the purpose.

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

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



Re: [PHP] POST without POSTing

2009-09-30 Thread Lars Torben Wilson
On Thu, 1 Oct 2009 00:24:41 -0400
Daniel Brown danbr...@php.net wrote:

 On Thu, Oct 1, 2009 at 00:16, Paul M Foster pa...@quillandmouse.com
 wrote:
 
  However, assuming it *wasn't*, I've found the following example
  from a google search (thank goodness for google's hinting or I
  couldn't have found it):
 
  $fp = fsockopen(www.site.com, 80);
  fputs($fp, POST /script.php HTTP/1.0
  Host: www.site.com
  Content-Length: 7
 
  q=proxy);
 
  I don't know much about doing things this way. It appears that when
  done this way, the body must be separated by a newline, just like
  email. And it appears that the content-length of 7 indicates the
  length of the q=proxy string. Assuming I piled on a few other
  passed variables the same way as q, separated by newlines (and
  adjusted the Content-Length accordingly), would the above work? Are
  there liabilities to doing it this way?
 
 Yes.  Hosts are more likely to have cURL installed and available
 than fsockopen() or URL-based fopen() calls, so portability is greater
 with cURL.  It's also a bit faster.  Still, as you know, there's
 always more than one way to skin a cute, furry, delicious little
 kitten.
 

I stand corrected on that point--in that way, yes, it would be a
liability. Happily it's been so long since I've had to use that kind of
host that I don't usually consider that a problem. But yes, if you're
using free or low-end hosting then you might have to contend with that.
Ugly, but true.


Torben

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