php-general Digest 3 Mar 2010 17:54:26 -0000 Issue 6619

2010-03-03 Thread php-general-digest-help

php-general Digest 3 Mar 2010 17:54:26 - Issue 6619

Topics (messages 302495 through 302514):

Re: When to use namespaces
302495 by: Adam Richardson

Re: inexplicable behaviour of pre- and post-increment operators
302496 by: Adam Richardson
302511 by: haliphax

Re: Wondering if anyone has experince with lastRSS
302497 by: Rene Veerman

Re: session.entropy_file and hostname
302498 by: Sascha Wojewsky
302502 by: Daniel Egeberg

Memory investigation
302499 by: Larry Garfield
302504 by: user.domain.invalid
302513 by: Larry Garfield
302514 by: David Otton

svg 2 gif/png
302500 by: Michael A. Peters
302501 by: Michael A. Peters
302503 by: Michael A. Peters
302505 by: Michael A. Peters

Help with exec.
302506 by: Paul Halliday
302507 by: Richard Quadling
302508 by: Teus Benschop
302509 by: Paul Halliday
302510 by: Ian
302512 by: Paul Halliday

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
Thanks, Richard, I wasn't aware of that function.  Another nice option.

On Tue, Mar 2, 2010 at 6:18 AM, Richard Quadling
rquadl...@googlemail.comwrote:

 On 1 March 2010 19:34, Adam Richardson simples...@gmail.com wrote:
  I use namespaces within my web framework because the framework takes a
 more
  functional approach (no objects are created within the framework other
 than
  from existing classes such as PDO or Exception, immutability is promoted,
  etc.), and in this context, the namespaces felt quite natural for
 breaking
  up the various groupings of functions.
 
  My framework does require PHP 5.3, and, honestly that has caused some
 pain
  in some situations to get that supported.
 
  However, using namespaces does offer some flexibility that naming
  conventions can't.  If the objects in your framework make use of frequent
  static method calls, maybe it's worth it.  For instance, if you've used
 the
  naming convention, you might have to call a static method like below:
 
  App_Util_DB_Query::Insert();
 
  Namespaces allow you to shorten subsequent calls, such as:
 
  use App\Util\DB\Query as Query;
 
  Query::Insert();
 
  Just a quick couple thoughts on the decision.  Both have their strengths
 :)
 
  Adam
 
  On Mon, Mar 1, 2010 at 11:14 AM, Auke van Slooten a...@muze.nl wrote:
 
  Hi everyone,
 
  I'm doing a small hobby project to better my understanding of php5,
  specifically php5.3 and I'm wondering when a namespaced project is
 better
  and when it is better to simply use a prefix to all class names.
 
  I've been trying to get a feeling for what is considered the best
 practice,
  but most of the pages dealing with namespaces start with the assumption
 that
  you are building a complex application with lots of modules and say
 things
  like:
 
  Namespaces should be all lowercase and must follow the following
 conention:
vendor\package_name\
 
  (thats from the php.standards mailing list btw)
 
  In my case the project is a single module, single php file, with about 6
  classes. It is an OO wrapper for PHP's xmlrpc methods (client and
 server)
  and meant to be used in a number of different projects.
 
  Is it considered a good idea to use a namespace in such a case? And if
 so,
  what should that be? I've named the project 'ripcord', and used that as
 a
  namespace as well. I could probably name it 'muze.ripcord', but somehow
 that
  feels less 'open' to me.
 
  Thanks in advance for any thoughts,
  Auke van Slooten
  Muze (www.muze.nl)
 
  PS. The project is at http://code.google.com/p/ripcord/, the PHP5.3
  version is at
  http://code.google.com/p/ripcord/source/browse/#svn/branches/php5.3
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
  --
  Nephtali:  PHP web framework that functions beautifully
  http://nephtaliproject.com
 

 Something I came across which has been useful in removing the long
 names (php5.3 namespaces), is the use of class_alias().

 My specific use is in DocBlocks for SOAP services. Using the Zend
 AutoLoader, my classes are structured so that
 Namespace_Package_Class_Exception is available in
 \includes\Namespace\Package\Class\Exception.php

 But having those long names in the SOAP WSDL file were a bit
 cumbersome. So by having a class_alias in the important class files
 (just after the class definition), I could use the alias names in the
 docblock and all is well.



 --
 -
 Richard Quadling
 Standing on the shoulders of some very clever giants!
 EE : http://www.experts-exchange.com/M_248814.html
 EE4Free : 

[PHP] svg 2 gif/png

2010-03-03 Thread Michael A. Peters

I'm moving all of my dynamic image generation to svg.
Not only does it look better, but it is less resource intensive on my 
server allowing me to generate the svg on demand instead of 
pre-generating (via cron) twice a month like I had to do with gd dynamic 
generation.


However, some browsers *cough*IE*cough* do not support SVG, so I still 
need png or gif fallback (I'll decide which after investigating size 
difference).


Example SVG to convert -

http://www.shastaherps.org/map/map22.svg

Using convert from ImageMagick in the CLI is fast enough that I may just 
use the ImageMagick php module and do the fallback dynamic for the IE 
users, but I've run into a bit of a snag - it seems that ImageMagick 
doesn't understand xlink.


IE running

convert --size=800x574 map22.svg map22.png

on above file results in a nice pretty map with the county and text, but 
the colored hexagons are not displayed.


Is there an easy way around this? IE a php class/function that 
understands SVG w/ xlink and can replace the use tags with the polygons 
they refer to? If not, I'll have to try to write one, but I'd rather not ...


Thanks for suggestions. It is too bad ImageMagick doesn't understand the 
use tag and xlink, that is one of the more useful features of SVG that I 
have personally found, makes dynamic generation so much easier.


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



Re: [PHP] svg 2 gif/png

2010-03-03 Thread Michael A. Peters

Michael A. Peters wrote:
*snip*


Is there an easy way around this? IE a php class/function that 
understands SVG w/ xlink and can replace the use tags with the polygons 
they refer to? If not, I'll have to try to write one, but I'd rather not 
...


I just did, haven't tested yet, but this may work -

function use2polygon($use,$polygon) {
   // get the xy coords
   $x = 0; $y = 0;
   if ($use-hasAttribute('x') {
  $x = 0 + $use-getAttribute('x');
  }
   if ($use-hasAttribute('y') {
  $y = 0 + $use-getAttribute('y');
  }
   // clone the polygon
   if ($polygon-hasAttribute('points') {
$points = preg_replace('/\s+/',' ',$polygon-getAttribute('points'));
  $pointArray = explode(' ',$points);
  $sizeof = sizeof($pointArray);
  for ($i=0;$i$sizeof;$i++) {
 $foo = explode(',',$pointArray[$i]);
 $foo[0] = $x + $foo[0];
 $foo[1] = $y + $foo[1];
 $pointArray[$i] = $foo[0] . ',' . $foo[1];
 }
  $points = implode(' ',$points);
  $newPolygon = $polygon-cloneNode(true);
  $newPolygon-setAttribute('points',$points);
  $use-parentNode-replaceChild($newPolygon,$use);
  }
   }

of course that requires domdocument and probably requires looping 
through the dom node list backwards, but hopefully that will do it.


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



Re: [PHP] session.entropy_file and hostname

2010-03-03 Thread Daniel Egeberg
On Wed, Mar 3, 2010 at 07:28, Sascha Wojewsky sascha.wojew...@heinze.de wrote:
 thank you for your answer,

 If you want server-unique session ids, use session_name() before
 session_start()..?

 i cannot use session_name, because i've to regenarete a session id by
 permanent login.
 i'm using session_regenerate_id, and session_name doesen't works with it (?)

It should work fine. You must change the session name (either using
the session_name() function or by changing session.name in php.ini)
before you call session_start().

Note that the session name and the session ID are two different things.

-- 
Daniel Egeberg

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



Re: [PHP] svg 2 gif/png

2010-03-03 Thread Michael A. Peters

Michael A. Peters wrote:

Michael A. Peters wrote:
*snip*


Is there an easy way around this? IE a php class/function that 
understands SVG w/ xlink and can replace the use tags with the 
polygons they refer to? If not, I'll have to try to write one, but I'd 
rather not ...


I just did, haven't tested yet, but this may work -


This does work (fixed version of function):

function use2polygon($use,$polygon) {
   // get the xy coords
   $x = 0; $y = 0;
   if ($use-hasAttribute('x')) {
  $x = 0 + $use-getAttribute('x');
  }
   if ($use-hasAttribute('y')) {
  $y = 0 + $use-getAttribute('y');
  }
   // clone the polygon
   if ($polygon-hasAttribute('points')) {
$points = preg_replace('/\s+/',' ',$polygon-getAttribute('points'));
  $pointArray = explode(' ',$points);
  $sizeof = sizeof($pointArray);
  for ($i=0;$i$sizeof;$i++) {
 $foo = explode(',',$pointArray[$i]);
 $foo[0] = $x + $foo[0];
 $foo[1] = $y + $foo[1];
 $pointArray[$i] = $foo[0] . ',' . $foo[1];
 }
  $points = implode(' ',$pointArray);
  $newPolygon = $polygon-cloneNode(true);
  $newPolygon-setAttribute('points',$points);
  $use-parentNode-replaceChild($newPolygon,$use);
  }
   }

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



[PHP] Re: Memory investigation

2010-03-03 Thread user
ON Linux I have kcacheGrind setup with Xdebug and I find it is a nice 
little thing to have. It won't tell you the memory consumed but it will 
find cycles and display object maps. if you have Kcachegrind it is 
likely you have valgrind installed.

http://www2.mandriva.com/
http://valgrind.org/
http://kcachegrind.sourceforge.net/html/Home.html
http://xdebug.org/
Larry Garfield wrote:
Hi folks.  I have a complicated PHP app that is eating up more memory than I 
think it should.  I have a couple of theories as to where it could be going, 
but I need some way to verify it.


There are a number of large data structures (mostly arrays) that get built up 
throughout the course of the request.  What I'd like to be able to do is at 
certain points check to see how much memory those data structures are using.  
Because they're not all built at once, the usual check memory before, build, 
check after routine won't work.  Plus, that gets screwed up by PHP's use of 
copy-on-write at times.


I know that it would result in essentially over-reporting, but I would ideally 
like to be able to ignore the copy-on-write issue and say if this variable 
were the only thing in memory (and its dependents, of course, for a nested 
array), what would its memory usage be?  I just have no idea how to do that.


Anyone have a suggestion for how to accomplish that?

--Larry Garfield


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



Re: [PHP] svg 2 gif/png

2010-03-03 Thread Michael A. Peters

Michael A. Peters wrote:

Michael A. Peters wrote:

Michael A. Peters wrote:
*snip*


Is there an easy way around this? IE a php class/function that 
understands SVG w/ xlink and can replace the use tags with the 
polygons they refer to? If not, I'll have to try to write one, but 
I'd rather not ...


I just did, haven't tested yet, but this may work -


This does work (fixed version of function):

function use2polygon($use,$polygon) {
   // get the xy coords
   $x = 0; $y = 0;
   if ($use-hasAttribute('x')) {
  $x = 0 + $use-getAttribute('x');
  }
   if ($use-hasAttribute('y')) {
  $y = 0 + $use-getAttribute('y');
  }
   // clone the polygon
   if ($polygon-hasAttribute('points')) {
$points = preg_replace('/\s+/',' ',$polygon-getAttribute('points'));
  $pointArray = explode(' ',$points);
  $sizeof = sizeof($pointArray);
  for ($i=0;$i$sizeof;$i++) {
 $foo = explode(',',$pointArray[$i]);
 $foo[0] = $x + $foo[0];
 $foo[1] = $y + $foo[1];
 $pointArray[$i] = $foo[0] . ',' . $foo[1];
 }
  $points = implode(' ',$pointArray);
  $newPolygon = $polygon-cloneNode(true);
  $newPolygon-setAttribute('points',$points);
  $use-parentNode-replaceChild($newPolygon,$use);
  }
   }



doh - for xml sanity, add this before the replaceChild

if ($newPolygon-hasAttribute('id')) {
 $newPolygon-removeAttribute('id');
 }

Now it works, and makes identical svg image that works with convert.

http://www.shastaherps.org/map/map22.svg vs
http://www.shastaherps.org/map/map22.svg?convert=true

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



[PHP] Help with exec.

2010-03-03 Thread Paul Halliday
I need to pipe some data to an external application.

I have this:

while ($row = mysql_fetch_array($theData[0])) {
$src_ip[] = $row[0];
$dst_ip[] = $row[1];
$sig_desc[] = $row[2];

$rec ++;
if ( $rec == $recCount ) {
break;
}
}

for ($i = 0; $i  sizeof($src_ip); $i++) {
$tmpResult[] = $sig_desc[$i],$src_ip[$i],$dst_ip[$i]\n;
}


The external program is called like:

cat results.csv | theprogram outputfilename

Is there a way mimic this w/o outputting $tmpResult to a file first?

Thanks.

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



Re: [PHP] Help with exec.

2010-03-03 Thread Richard Quadling
On 3 March 2010 13:01, Paul Halliday paul.halli...@gmail.com wrote:
 I need to pipe some data to an external application.

 I have this:

 while ($row = mysql_fetch_array($theData[0])) {
    $src_ip[] = $row[0];
    $dst_ip[] = $row[1];
    $sig_desc[] = $row[2];

    $rec ++;
    if ( $rec == $recCount ) {
            break;
    }
 }

 for ($i = 0; $i  sizeof($src_ip); $i++) {
    $tmpResult[] = $sig_desc[$i],$src_ip[$i],$dst_ip[$i]\n;
 }


 The external program is called like:

 cat results.csv | theprogram outputfilename

 Is there a way mimic this w/o outputting $tmpResult to a file first?

 Thanks.

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



I believe you can use popen() to open theprogram and pipe to it the
content and read back the results. All without writing to any files.



-- 
-
Richard Quadling
Standing on the shoulders of some very clever giants!
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



Re: [PHP] Help with exec.

2010-03-03 Thread Teus Benschop
On Wed, 2010-03-03 at 13:04 +, Richard Quadling wrote:
 On 3 March 2010 13:01, Paul Halliday paul.halli...@gmail.com wrote:
  I need to pipe some data to an external application.
 
  I have this:
 
  while ($row = mysql_fetch_array($theData[0])) {
 $src_ip[] = $row[0];
 $dst_ip[] = $row[1];
 $sig_desc[] = $row[2];
 
 $rec ++;
 if ( $rec == $recCount ) {
 break;
 }
  }
 
  for ($i = 0; $i  sizeof($src_ip); $i++) {
 $tmpResult[] = $sig_desc[$i],$src_ip[$i],$dst_ip[$i]\n;
  }
 
 
  The external program is called like:
 
  cat results.csv | theprogram outputfilename
 
  Is there a way mimic this w/o outputting $tmpResult to a file first?
 
  Thanks.
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 I believe you can use popen() to open theprogram and pipe to it the
 content and read back the results. All without writing to any files.
 

popen() either reads from a pipe or writes to a pipe, if I remember
well, not both. Teus.



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



Re: [PHP] Help with exec.

2010-03-03 Thread Paul Halliday
I work by example :)

I can't find enough of an example to get me going with this.

I have this:

$glow = popen('afterglow.pl -c color.properties -s -e 3 -p 1 -l 2000 |
neato -Tpng -o /usr/local/www/test.png','r');

how do I feed my array to that?

Thanks.

On Wed, Mar 3, 2010 at 9:04 AM, Richard Quadling
rquadl...@googlemail.com wrote:
 On 3 March 2010 13:01, Paul Halliday paul.halli...@gmail.com wrote:
 I need to pipe some data to an external application.

 I have this:

 while ($row = mysql_fetch_array($theData[0])) {
    $src_ip[] = $row[0];
    $dst_ip[] = $row[1];
    $sig_desc[] = $row[2];

    $rec ++;
    if ( $rec == $recCount ) {
            break;
    }
 }

 for ($i = 0; $i  sizeof($src_ip); $i++) {
    $tmpResult[] = $sig_desc[$i],$src_ip[$i],$dst_ip[$i]\n;
 }


 The external program is called like:

 cat results.csv | theprogram outputfilename

 Is there a way mimic this w/o outputting $tmpResult to a file first?

 Thanks.

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



 I believe you can use popen() to open theprogram and pipe to it the
 content and read back the results. All without writing to any files.



 --
 -
 Richard Quadling
 Standing on the shoulders of some very clever giants!
 EE : http://www.experts-exchange.com/M_248814.html
 EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
 Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
 ZOPA : http://uk.zopa.com/member/RQuadling


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



[PHP] Re: Help with exec.

2010-03-03 Thread Ian
On 03/03/2010 13:01, Paul Halliday wrote:
 I need to pipe some data to an external application.
 
 I have this:
 
 while ($row = mysql_fetch_array($theData[0])) {
 $src_ip[] = $row[0];
 $dst_ip[] = $row[1];
 $sig_desc[] = $row[2];
 
 $rec ++;
 if ( $rec == $recCount ) {
 break;
 }
 }
 
 for ($i = 0; $i  sizeof($src_ip); $i++) {
 $tmpResult[] = $sig_desc[$i],$src_ip[$i],$dst_ip[$i]\n;
 }
 
 
 The external program is called like:
 
 cat results.csv | theprogram outputfilename
 
 Is there a way mimic this w/o outputting $tmpResult to a file first?
 
 Thanks.
 

Hi,

I have used this code to feed data to gpg and read back the encrypted
result, Im sure you can adapt it to your needs.

function Encrypt($data){

# http://www.theoslogic.com/scripts/php-gpg/

$gpg_command=/usr/bin/gpg $parameters;

$errLog = /tmp/errors.log;

$dspecs = array(
0=array(pipe, r),
1=array(pipe, w),
2=array(file, $errLog, a)
);

$encrypted=;
$procdata=;

$gpgproc = proc_open($gpg_command, $dspecs, $pipes);

if (is_resource($gpgproc)) {
fwrite($pipes[0], $data);
fclose($pipes[0]);

while($procdata = fgets($pipes[1], 1024)) {
$encrypted .= $procdata;
}
fclose($pipes[1]);
}

return $encrypted;
}

It works really well.

Regards

Ian
-- 


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



Re: [PHP] PHP: inexplicable behaviour of pre- and post-increment operators

2010-03-03 Thread haliphax
 On Fri, Feb 26, 2010 at 11:01 PM, clanc...@cybec.com.au wrote:
  while ($i  $j) { $b[$i] = $a[$i++]; }  B.
 
  You get $b[0] = $a[1], and so on (as you would expect).


Wouldn't that be $b[0] = $a[0], with the value of $i being 1 *after* the
statement was finished executing? You used a post-decrement operator on $i
at the end of your statement, so I don't think that $i would be increased
before being used to index into the $a array.


// Todd


Re: [PHP] Re: Help with exec.

2010-03-03 Thread Paul Halliday
and its that easy!

it took me a minute to figure out; but all I had to do was:

if (is_resource($process)) {

for ($i = 0; $i  sizeof($src_ip); $i++) {
fwrite($pipes[0], $sig_desc[$i],$src_ip[$i],$dst_ip[$i]\n);
}

fclose($pipes[0]);
fclose($pipes[1]);
proc_close($process);
}

thanks.

On Wed, Mar 3, 2010 at 10:08 AM, Ian php_l...@fishnet.co.uk wrote:
 On 03/03/2010 13:01, Paul Halliday wrote:
 I need to pipe some data to an external application.

 I have this:

 while ($row = mysql_fetch_array($theData[0])) {
     $src_ip[] = $row[0];
     $dst_ip[] = $row[1];
     $sig_desc[] = $row[2];

     $rec ++;
     if ( $rec == $recCount ) {
             break;
     }
 }

 for ($i = 0; $i  sizeof($src_ip); $i++) {
     $tmpResult[] = $sig_desc[$i],$src_ip[$i],$dst_ip[$i]\n;
 }


 The external program is called like:

 cat results.csv | theprogram outputfilename

 Is there a way mimic this w/o outputting $tmpResult to a file first?

 Thanks.


 Hi,

 I have used this code to feed data to gpg and read back the encrypted
 result, Im sure you can adapt it to your needs.

 function Encrypt($data){

        # http://www.theoslogic.com/scripts/php-gpg/

        $gpg_command=/usr/bin/gpg $parameters;

        $errLog = /tmp/errors.log;

        $dspecs = array(
                0=array(pipe, r),
                1=array(pipe, w),
                2=array(file, $errLog, a)
        );

        $encrypted=;
        $procdata=;

        $gpgproc = proc_open($gpg_command, $dspecs, $pipes);

        if (is_resource($gpgproc)) {
                fwrite($pipes[0], $data);
                fclose($pipes[0]);

                while($procdata = fgets($pipes[1], 1024)) {
                        $encrypted .= $procdata;
                }
                fclose($pipes[1]);
        }

        return $encrypted;
 }

 It works really well.

 Regards

 Ian
 --


 --
 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] Re: Memory investigation

2010-03-03 Thread la...@garfieldtech.com
Yep, I'm familiar with XDebug and KCacheGrind.  As you say, though, it 
doens't (as far as I am aware) offer the particular data that I'm after. 
 We've already got cachegrind gurus working on the code who know how to 
use it better than I do. :-)  What I'm looking for is see this big 
cache object we've been building up in memory for this whole page 
request?  Now that we're done with the page, how big is it, really?


--Larry Garfield

u...@domain.invalid wrote:
ON Linux I have kcacheGrind setup with Xdebug and I find it is a nice 
little thing to have. It won't tell you the memory consumed but it will 
find cycles and display object maps. if you have Kcachegrind it is 
likely you have valgrind installed.

http://www2.mandriva.com/
http://valgrind.org/
http://kcachegrind.sourceforge.net/html/Home.html
http://xdebug.org/
Larry Garfield wrote:
Hi folks.  I have a complicated PHP app that is eating up more memory 
than I think it should.  I have a couple of theories as to where it 
could be going, but I need some way to verify it.


There are a number of large data structures (mostly arrays) that get 
built up throughout the course of the request.  What I'd like to be 
able to do is at certain points check to see how much memory those 
data structures are using.  Because they're not all built at once, the 
usual check memory before, build, check after routine won't work.  
Plus, that gets screwed up by PHP's use of copy-on-write at times.


I know that it would result in essentially over-reporting, but I would 
ideally like to be able to ignore the copy-on-write issue and say if 
this variable were the only thing in memory (and its dependents, of 
course, for a nested array), what would its memory usage be?  I just 
have no idea how to do that.


Anyone have a suggestion for how to accomplish that?

--Larry Garfield




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



Re: [PHP] Re: Memory investigation

2010-03-03 Thread David Otton
On 3 March 2010 15:49, la...@garfieldtech.com la...@garfieldtech.com wrote:

 Yep, I'm familiar with XDebug and KCacheGrind.  As you say, though, it
 doens't (as far as I am aware) offer the particular data that I'm after.
  We've already got cachegrind gurus working on the code who know how to use
 it better than I do. :-)  What I'm looking for is see this big cache object
 we've been building up in memory for this whole page request?  Now that
 we're done with the page, how big is it, really?

You could try Memtrack (http://pecl.php.net/package/memtrack) but I
can't comment as to what state it's in.

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



Re: [PHP] Re: Memory investigation

2010-03-03 Thread dsiembab01

function check_memory_usage($memory)
{
$memory[] = memory_get_usage();
return $memory;
}

something like this?
you can put it wherever you like and returns an array for further 
processing. You could optionally add a second argument to set the index 
to a name and check if the name exists to add 1 to the end of the name 
so your indexes stay maintained.


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



Re: [PHP] Re: Memory investigation

2010-03-03 Thread la...@garfieldtech.com

That's not really what I'm after.  Let me try an example:

function foo($id) {
  static $foos = array();

  if (empty($foos[$id]) {
$foos[$id] = load_foo($id);
  }
  return $foos[$id];
}

When load_foo() is slow (e.g., lots of DB traffic or remote-server calls 
or whatever), such caching can have a significant performance boost. 
Sometime after foo() has been called 15 times from 30 places in code, 
when I get to the end of the request (or just every time I call foo() 
would be fine) I want to be able to do something like:


$cost = get_memory_used_by($foos);

So that I can determine how much memory that caching is costing me over 
the lifetime of the page, and determine if it's a worthwhile trade-off.


--Larry Garfield

dsiemba...@gmail.com wrote:

function check_memory_usage($memory)
{
$memory[] = memory_get_usage();
return $memory;
}

something like this?
you can put it wherever you like and returns an array for further 
processing. You could optionally add a second argument to set the index 
to a name and check if the name exists to add 1 to the end of the name 
so your indexes stay maintained.




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



[PHP] Re: Database design

2010-03-03 Thread dsiembab01

a good tool for mapping mysql databases is mysql-workbench.
the real question is how much normalization is normal?
http://wb.mysql.com

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



[PHP] basic authentication and redirection

2010-03-03 Thread Bill Rausch



Hi there,

In certain circumstances controlled by my users, I'd like to redirect 
my users to another site, a third party whom we have contracted with. 
The second site uses basic authentication with a simple username and 
password. Can I write my PHP code so my users do not have to login 
(or even know the username/password) on the remote site?


This isn't intended to stop serious hackers, just enough security to 
stop casual passers-by.


Thanks,

Bill


--
Bill Rausch

We first make our habits and then our habits make us. --John Dryden

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



[PHP] Best os shopping cart

2010-03-03 Thread Haig Davis
Hi,

I apologise if this is not strictly php related. What Open Source Shopping
cart system do you recommend between osCommerce and Zen-Cart for ease of use
and a php guy with dangerously little javascript knowledge?

This is not for a massive shopping site, simply a cart to power a
subscription sign-up page.

Thanks for the advice.

Haig


Re: [PHP] Best os shopping cart

2010-03-03 Thread Robert Cummings

Haig Davis wrote:

Hi,

I apologise if this is not strictly php related. What Open Source Shopping
cart system do you recommend between osCommerce and Zen-Cart for ease of use
and a php guy with dangerously little javascript knowledge?

This is not for a massive shopping site, simply a cart to power a
subscription sign-up page.


At this point in time I would choose ZenCart over osCommerce since 
development of osCommerce has languished for the past 3+ years at 
version 2.2 and version 3.0 has been in alpha for just as long.


Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



Re: [PHP] basic authentication and redirection

2010-03-03 Thread Rene Veerman
depends on how that site does its authentication...

if it's a form, it may need an extra setting to allow you to go to a
specific page on that site after authentication.

On Wed, Mar 3, 2010 at 8:25 PM, Bill Rausch brau...@owt.com wrote:


 Hi there,

 In certain circumstances controlled by my users, I'd like to redirect my
 users to another site, a third party whom we have contracted with. The
 second site uses basic authentication with a simple username and password.
 Can I write my PHP code so my users do not have to login (or even know the
 username/password) on the remote site?

 This isn't intended to stop serious hackers, just enough security to stop
 casual passers-by.

 Thanks,

 Bill


 --
 Bill Rausch

 We first make our habits and then our habits make us. --John Dryden

 --
 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] Re: Memory investigation

2010-03-03 Thread Rene Veerman
global $fooSize = 0;

function foo($id) {

global $fooSize;
if (empty($foos($id)) {
  $b = get_memory_usage(true);
  $foos[$id] = load_foo($id);
  $fooSize+= $b - get_memory_usage(true);
}
...
}
On Wed, Mar 3, 2010 at 8:16 PM, la...@garfieldtech.com
la...@garfieldtech.com wrote:
 That's not really what I'm after.  Let me try an example:

 function foo($id) {
  static $foos = array();

  if (empty($foos[$id]) {
    $foos[$id] = load_foo($id);
  }
  return $foos[$id];
 }

 When load_foo() is slow (e.g., lots of DB traffic or remote-server calls or
 whatever), such caching can have a significant performance boost. Sometime
 after foo() has been called 15 times from 30 places in code, when I get to
 the end of the request (or just every time I call foo() would be fine) I
 want to be able to do something like:

 $cost = get_memory_used_by($foos);

 So that I can determine how much memory that caching is costing me over the
 lifetime of the page, and determine if it's a worthwhile trade-off.

 --Larry Garfield

 dsiemba...@gmail.com wrote:

 function check_memory_usage($memory)
 {
    $memory[] = memory_get_usage();
    return $memory;
 }

 something like this?
 you can put it wherever you like and returns an array for further
 processing. You could optionally add a second argument to set the index to a
 name and check if the name exists to add 1 to the end of the name so your
 indexes stay maintained.


 --
 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] basic authentication and redirection

2010-03-03 Thread Jay Blanchard
[snip]
In certain circumstances controlled by my users, I'd like to redirect 
my users to another site, a third party whom we have contracted with. 
The second site uses basic authentication with a simple username and 
password. Can I write my PHP code so my users do not have to login 
(or even know the username/password) on the remote site?

This isn't intended to stop serious hackers, just enough security to 
stop casual passers-by.
[/snip]

Have a look at cURL (http://www.php.net/curl) as it will allow you to
perform remote POST's which may be enough to get you through.

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



Re: [PHP] basic authentication and redirection

2010-03-03 Thread Robert Cummings

Jay Blanchard wrote:

[snip]
In certain circumstances controlled by my users, I'd like to redirect 
my users to another site, a third party whom we have contracted with. 
The second site uses basic authentication with a simple username and 
password. Can I write my PHP code so my users do not have to login 
(or even know the username/password) on the remote site?


This isn't intended to stop serious hackers, just enough security to 
stop casual passers-by.

[/snip]

Have a look at cURL (http://www.php.net/curl) as it will allow you to
perform remote POST's which may be enough to get you through.


Or you can use JavaScript on an intermediate page to post directly to 
the remote site's login form. If JavaScript is disabled, just have a 
button Please continue to XXX which then performs the post tot he 
remote site.


Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



Re: [PHP] Re: Memory investigation

2010-03-03 Thread dsiembab01
couple questions Larry is this application composed of classes or 
straight up no holes barred procedural code?


la...@garfieldtech.com wrote:

That's not really what I'm after.  Let me try an example:

function foo($id) {
  static $foos = array();

  if (empty($foos[$id]) {
$foos[$id] = load_foo($id);
  }
  return $foos[$id];
}

When load_foo() is slow (e.g., lots of DB traffic or remote-server calls 
or whatever), such caching can have a significant performance boost. 
Sometime after foo() has been called 15 times from 30 places in code, 
when I get to the end of the request (or just every time I call foo() 
would be fine) I want to be able to do something like:


$cost = get_memory_used_by($foos);

So that I can determine how much memory that caching is costing me over 
the lifetime of the page, and determine if it's a worthwhile trade-off.


--Larry Garfield

dsiemba...@gmail.com wrote:

function check_memory_usage($memory)
{
$memory[] = memory_get_usage();
return $memory;
}

something like this?
you can put it wherever you like and returns an array for further 
processing. You could optionally add a second argument to set the 
index to a name and check if the name exists to add 1 to the end of 
the name so your indexes stay maintained.




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



Re: [PHP] Re: Memory investigation

2010-03-03 Thread la...@garfieldtech.com
Currently it's mostly procedural with some components that are OO.  I 
suspect most of the memory sinks are large arrays (we have a lot of 
them), but I am not certain of that.  Hence my interest in more accurate 
investigation tools.


--Larry Garfield

dsiemba...@gmail.com wrote:
couple questions Larry is this application composed of classes or 
straight up no holes barred procedural code?


la...@garfieldtech.com wrote:

That's not really what I'm after.  Let me try an example:

function foo($id) {
  static $foos = array();

  if (empty($foos[$id]) {
$foos[$id] = load_foo($id);
  }
  return $foos[$id];
}

When load_foo() is slow (e.g., lots of DB traffic or remote-server 
calls or whatever), such caching can have a significant performance 
boost. Sometime after foo() has been called 15 times from 30 places in 
code, when I get to the end of the request (or just every time I call 
foo() would be fine) I want to be able to do something like:


$cost = get_memory_used_by($foos);

So that I can determine how much memory that caching is costing me 
over the lifetime of the page, and determine if it's a worthwhile 
trade-off.


--Larry Garfield

dsiemba...@gmail.com wrote:

function check_memory_usage($memory)
{
$memory[] = memory_get_usage();
return $memory;
}

something like this?
you can put it wherever you like and returns an array for further 
processing. You could optionally add a second argument to set the 
index to a name and check if the name exists to add 1 to the end of 
the name so your indexes stay maintained.






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



Re: [PHP] Best os shopping cart

2010-03-03 Thread Ashley Sheridan
On Wed, 2010-03-03 at 14:46 -0500, Robert Cummings wrote:

 Haig Davis wrote:
  Hi,
  
  I apologise if this is not strictly php related. What Open Source Shopping
  cart system do you recommend between osCommerce and Zen-Cart for ease of use
  and a php guy with dangerously little javascript knowledge?
  
  This is not for a massive shopping site, simply a cart to power a
  subscription sign-up page.
 
 At this point in time I would choose ZenCart over osCommerce since 
 development of osCommerce has languished for the past 3+ years at 
 version 2.2 and version 3.0 has been in alpha for just as long.
 
 Cheers,
 Rob.
 -- 
 http://www.interjinn.com
 Application and Templating Framework for PHP
 


If it's an option, I'd recommend Magento. I've not used it, but I've
heard a lot of good things about it.

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




Re: [PHP] Best os shopping cart

2010-03-03 Thread tedd

At 11:29 AM -0800 3/3/10, Haig Davis wrote:

Hi,

I apologise if this is not strictly php related. What Open Source Shopping
cart system do you recommend between osCommerce and Zen-Cart for ease of use
and a php guy with dangerously little javascript knowledge?

This is not for a massive shopping site, simply a cart to power a
subscription sign-up page.

Thanks for the advice.

Haig


Haig:

A subscription sign-up page? That doesn't sound like a shopping cart problem.

You mean something like this:

http://webbytedd.com/b/sub-email/

Cheers,

tedd


--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



[PHP] Re: Best os shopping cart

2010-03-03 Thread Shawn McKenzie
Haig Davis wrote:
 Hi,
 
 I apologise if this is not strictly php related. What Open Source Shopping
 cart system do you recommend between osCommerce and Zen-Cart for ease of use
 and a php guy with dangerously little javascript knowledge?
 
 This is not for a massive shopping site, simply a cart to power a
 subscription sign-up page.
 
 Thanks for the advice.
 
 Haig
 

For just a subscription sign-up I use a PayPal button.  PayPal supports
subscription based billing.


-- 
Thanks!
-Shawn
http://www.spidean.com

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



Re: [PHP] PHP: inexplicable behaviour of pre- and post-increment operators

2010-03-03 Thread clancy_1
On Wed, 3 Mar 2010 08:21:06 -0600, halip...@gmail.com (haliphax) wrote:

 On Fri, Feb 26, 2010 at 11:01 PM, clanc...@cybec.com.au wrote:
  while ($i  $j) { $b[$i] = $a[$i++]; }  B.
 
  You get $b[0] = $a[1], and so on (as you would expect).


Wouldn't that be $b[0] = $a[0], with the value of $i being 1 *after* the
statement was finished executing? You used a post-decrement operator on $i
at the end of your statement, so I don't think that $i would be increased
before being used to index into the $a array.

Try it!

Clancy

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



[PHP] XMLRPC issue

2010-03-03 Thread Dmitry Ruban

Hi all,

I was upgrading php from 5.6 to 5.11 and came across one odd issue. Hope 
someone could point out what is the problem.


Following code demonstrates it:

$xml = '?xml version=1.0 
encoding=UTF-8?methodResponseparamsparamvaluelt;Test/gt;/value/param/params/methodResponse';


echo xmlrpc_decode($xml);

I suspect to get Test/ as a result, but for some reason  and  are 
cut out and i'm getting Test/. So basically all entities are dropped 
from response.


I have 2nd server running same OS (CentOS 5) which has been upgraded 
first and it works as i suspect, code above shows Test/.


Any advice will be much appreciated.

Currently I have temporary workaround for this:

$xml = str_replace(array('lt;','gt;'), array('#60;','#62;'), $xml);

but would like to fix xmlrpc somehow.

Regards,
Dmitry Ruban




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