[PHP] mcrypt_create_iv - why so slow?

2013-05-31 Thread Nathan Nobbe
Hi folks,

This code:

?php
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,
MCRYPT_MODE_CBC), MCRYPT_DEV_RANDOM);
var_dump($iv);

Takes just over a minute to run on my laptop and roughly 45 seconds on a
capable server, any idea why?

time php test-iv.php
string(32) '???H??y?PJ?U?1O;6???ѧ

real 0m44.917s
user 0m0.024s
sys 0m0.036s

Also, I've noticed the mcrypt_encypt  mcrypt_decrypt complain with

The IV parameter must be as long as the blocksize

when not using mcrypt_create_iv, however, if the value of the IV parameter
is consistent in both calls, the decryption seems to succeed despite the
warning.

So wondering:
* can the call to mcrypt_create_iv be sped up
* is there an alternative (faster) way to create a proper iv
* how big a risk is it to 'ride dirty' here and not use mcrypt_create_iv

thanks,

-nathan


[PHP] Re: mcrypt_create_iv - why so slow?

2013-05-31 Thread Nathan Nobbe
Interesting, using MCRYPT_DEV_URANDOM instead of MCRYPT_DEV_RANDOM seems
practically instantaneous.

Another less elegant solution I've found is to simply str_pad to the length
returned by mcrypt_get_iv_size.

Still begs the question though, any idea what's holding up the show w/
MCRYPT_DEV_RANDOM?  #morbidcuriosity

-nathan


On Fri, May 31, 2013 at 12:40 AM, Nathan Nobbe quickshif...@gmail.comwrote:

 Hi folks,

 This code:

 ?php
 $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,
 MCRYPT_MODE_CBC), MCRYPT_DEV_RANDOM);
 var_dump($iv);

 Takes just over a minute to run on my laptop and roughly 45 seconds on a
 capable server, any idea why?

 time php test-iv.php
 string(32) '???H??y?PJ?U?1O;6???ѧ

 real 0m44.917s
 user 0m0.024s
 sys 0m0.036s

 Also, I've noticed the mcrypt_encypt  mcrypt_decrypt complain with

 The IV parameter must be as long as the blocksize

 when not using mcrypt_create_iv, however, if the value of the IV parameter
 is consistent in both calls, the decryption seems to succeed despite the
 warning.

 So wondering:
 * can the call to mcrypt_create_iv be sped up
 * is there an alternative (faster) way to create a proper iv
 * how big a risk is it to 'ride dirty' here and not use mcrypt_create_iv

 thanks,

 -nathan



Re: [PHP] Is there a PHP based authentication library?

2013-04-02 Thread Nathan Nobbe
On Tue, Apr 2, 2013 at 3:35 PM, Mark mark...@gmail.com wrote:

 Hi Bastien,

 That is indeed getting very close to what i was looking for. Thanks a lot!


I've just finished up a project using simpleSamlPhp.

http://simplesamlphp.org/

There's quite a few modules, but I've only used the SAML one, so YMMV.

-nathan

bash-3.2$ ls -1 modules/
InfoCard
adfs
aggregator
aggregator2
aselect
authX509
authYubiKey
authcrypt
authfacebook
authlinkedin
authmyspace
authorize
authtwitter
authwindowslive
autotest
cas
casserver
cdc
consent
consentAdmin
consentSimpleAdmin
core
cron
discopower
exampleattributeserver
exampleauth
expirycheck
ldap
logpeek
memcacheMonitor
metaedit
metarefresh
modinfo
multiauth
negotiate
oauth
openid
openidProvider
papi
portal
preprodwarning
radius
riak
saml
saml2debug
sanitycheck
smartnameattribute
sqlauth
statistics
themefeidernd


Re: [PHP] Strange string stuff -- maybe everything is ending...

2012-12-21 Thread Nathan Nobbe
On Fri, Dec 21, 2012 at 3:27 PM, Jim Giner jim.gi...@albanyhandball.comwrote:

 On 12/21/2012 5:16 PM, Tedd Sperling wrote:

 On Dec 21, 2012, at 4:58 PM, Jim Giner jim.gi...@albanyhandball.com
 wrote:


  Never realized that you could address a string as an array of chars,
 which you are doing.  Could that be the issue?  Or did I learn something
 new?  Or should you have used substr to remove that last char?


 Jim:

 I guess you learned something new -- that's good.

 A string is just a string of chars.

 As such, if you define:

 $a = tedd;

 then:

 $a[0] is 't';
 $a[1] is 'e'
 $a[2] is 'd'
 $a[3] is 'd'

 The only confusing thing here is the length of the string -- in this case
 the length of this string is four, but $a[4] has not been defined.

 Cheers,

 tedd

 _
 t...@sperling.com
 http://sperling.com



  From what I do know, there shouldn't be an a[4].
 In any case, let's assume that there is a bug in the string logic that
 you're using.  Why not just use substr?

 $topic = substr($topic,0,-1);



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


Neat idea Tedd, but judging by a quick test, I don't think changing the
value of the string is entirely supported though that notation.

php  $str = 'blah';
php  $str[3] = '';
php  echo $str . PHP_EOL;
bla
php  echo strlen($str);
4


-nathan


Re: [PHP] Strange string stuff -- maybe everything is ending...

2012-12-21 Thread Nathan Nobbe
On Fri, Dec 21, 2012 at 4:10 PM, Nathan Nobbe quickshif...@gmail.comwrote:



 On Fri, Dec 21, 2012 at 3:27 PM, Jim Giner 
 jim.gi...@albanyhandball.comwrote:

 On 12/21/2012 5:16 PM, Tedd Sperling wrote:

 On Dec 21, 2012, at 4:58 PM, Jim Giner jim.gi...@albanyhandball.com
 wrote:


  Never realized that you could address a string as an array of chars,
 which you are doing.  Could that be the issue?  Or did I learn something
 new?  Or should you have used substr to remove that last char?


 Jim:

 I guess you learned something new -- that's good.

 A string is just a string of chars.

 As such, if you define:

 $a = tedd;

 then:

 $a[0] is 't';
 $a[1] is 'e'
 $a[2] is 'd'
 $a[3] is 'd'

 The only confusing thing here is the length of the string -- in this
 case the length of this string is four, but $a[4] has not been defined.

 Cheers,

 tedd

 _
 t...@sperling.com
 http://sperling.com



  From what I do know, there shouldn't be an a[4].
 In any case, let's assume that there is a bug in the string logic that
 you're using.  Why not just use substr?

 $topic = substr($topic,0,-1);



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


 Neat idea Tedd, but judging by a quick test, I don't think changing the
 value of the string is entirely supported though that notation.

 php  $str = 'blah';
 php  $str[3] = '';
 php  echo $str . PHP_EOL;
 bla
 php  echo strlen($str);
 4


Another interesting twist along the same lines, seems the string offsets
are indeed read only:

php  unset($str[3]);

Fatal error: Cannot unset string offsets in php shell code on line 1

Call Stack:
 6665.6475 384568   1. {main}() php shell code:0

-nathan


Re: [PHP] Variables with - in their name

2012-11-18 Thread Nathan Nobbe
On Sat, Nov 17, 2012 at 11:09 PM, Ron Piggott 
ron.pigg...@actsministries.org wrote:

 I have made the following variable in a form:  (I am referring the
 select )

 ?php

 $row['promo_code_prefix']  = 42;
 $row['promo_code_suffix'] = 2;

 echo select name=\distributor- . $row['promo_code_prefix'] . - .
 $row['promo_code_suffix'] . \ style=\text-align: center;\\r\n;

 ?

 It could be wrote:

 ?php

 echo  $distributor-42-2;

 ?

 Only PHP is treating the hyphen as a minus sign --- which in turn is
 causing a syntax error.

 How do I retrieve the value of this variable and over come the “minus”
 sign that is really a hyphen?


php  ${distributor-42-2} = 5;
php  echo ${distributor-42-2};
5

I think that's it.

-nathan


Re: [PHP] PDO

2012-10-22 Thread Nathan Nobbe
On Mon, Oct 22, 2012 at 3:27 PM, Silvio Siefke siefke_lis...@web.de wrote:

 Hello,

 i have built php 5.4.7 on Ubuntu with the configure Arguments like on my
 Gentoo System. But on Gentoo run the website without Problems, under Ubuntu
 want not work. I become in error.log:

 [22-Oct-2012 21:15:00 UTC] PHP Fatal error:  Call to a member function
 prepare() on a non-object in html/index.html on line 23

 U use PHP FPM with Nginx.

 The configure Arguments:
 http://pastebin.geany.org/qz8TP/

 The Script which work:
 ?php
 require_once (db.php);

 $query = $db-prepare(SELECT id, title, date FROM bloggen ORDER BY date
 DESC LIMIT 0,5);
 if (!$query) {die(Execute query error, because:  . $db-errorInfo());}


That looks like you've not connected to the database successfully inside of
db.php.

-nathan


[PHP] APC expunge notices

2012-08-17 Thread Nathan Nobbe
Hi everyone,

I'd like to see what other folks think about the idea of having APC provide
a E_WARNING or E_NOTICE when it has to expunge the cache.  Ideally, this
would include the amount of memory allocated in the error message.

The idea here is to provide system admins with information that

A. The cache had to be expunged
B. The amount of memory allocated when the cache had to be expunged

Right now, unless a close eye is kept, how is one to garner this
information.

Maybe, if the idea is interesting, it could be expanded to allow a user
defined callback method where custom behavior could be implemented.

Your feedback appreciated,

-nathan


[PHP] Bazar behavior w/ private member variables

2012-07-12 Thread Nathan Nobbe
Hi all,

Strangely PHP seems to let each class have its own layer of private scope
for member variables.  If a subclass defines a member variable of the same
name as one defined in the parent the values are maintained independently
in instances of the  child class.

First off a simple class with a private member variable $_myPrivate, and a
public accessor method which returns its value:

class A
{
private $_myPrivate = 5;

public function getMyPrivate()
{
return $this-_myPrivate;
}
}


Second, a subclass, that gets weird right away, first we define a private
member variable that already has been defined in the parent class, and give
it a different initial value.  To illustrate the behavior we have two
accessor methods, setMyPrivate that uses the $this keyword to get the value
of $_myPrivate, which returns the value of the subclasse's version of the
variable, and getParentsMyPrivate, that calls A::getMyPrivate via the
parent keyword and it returns the value of $_myPrivate as defined in the
base class.

class B extends A
{
private $_myPrivate = 6;

public function setMyPrivate()
{
$this-_myPrivate = 6;
}

public function getMyPrivate()
{
return $this-_myPrivate;
}

public function getParentsMyPrivate()
{
return parent::getMyPrivate();
}
}


Look at a var_dump of an instance of B:

object(B)#2 (2) {
  [_myPrivate:B:private]=
  int(6)
  [_myPrivate:A:private]=
  int(5)
}

clearly storage is allocated for two different values.  Now I'm sure you
all know that if I were to define a private method in A and try to call it
from B a Fatal error is raised, something on the order of

PHP Fatal error:  Call to private method A::tryToCallMeFromB() from context
'B'

so why the special treatment for member variables, is this supposed to be a
feature?

-nathan


Re: [PHP] Bazar behavior w/ private member variables

2012-07-12 Thread Nathan Nobbe
On Thu, Jul 12, 2012 at 8:38 PM, Tommy Pham tommy...@gmail.com wrote:

 On Thu, Jul 12, 2012 at 7:19 PM, Nathan Nobbe quickshif...@gmail.com
 wrote:
  Hi all,
 
  Strangely PHP seems to let each class have its own layer of private scope
  for member variables.  If a subclass defines a member variable of the
 same
  name as one defined in the parent the values are maintained independently
  in instances of the  child class.
 
  First off a simple class with a private member variable $_myPrivate, and
 a
  public accessor method which returns its value:
 
  class A
  {
  private $_myPrivate = 5;
 
  public function getMyPrivate()
  {
  return $this-_myPrivate;
  }
  }
 
 
  Second, a subclass, that gets weird right away, first we define a private
  member variable that already has been defined in the parent class, and
 give
  it a different initial value.  To illustrate the behavior we have two
  accessor methods, setMyPrivate that uses the $this keyword to get the
 value
  of $_myPrivate, which returns the value of the subclasse's version of the
  variable, and getParentsMyPrivate, that calls A::getMyPrivate via the
  parent keyword and it returns the value of $_myPrivate as defined in the
  base class.
 
  class B extends A
  {
  private $_myPrivate = 6;
 
  public function setMyPrivate()
  {
  $this-_myPrivate = 6;
  }
 
  public function getMyPrivate()
  {
  return $this-_myPrivate;
  }
 
  public function getParentsMyPrivate()
  {
  return parent::getMyPrivate();
  }
  }
 
 
  Look at a var_dump of an instance of B:
 
  object(B)#2 (2) {
[_myPrivate:B:private]=
int(6)
[_myPrivate:A:private]=
int(5)
  }
 
  clearly storage is allocated for two different values.  Now I'm sure you
  all know that if I were to define a private method in A and try to call
 it
  from B a Fatal error is raised, something on the order of
 
  PHP Fatal error:  Call to private method A::tryToCallMeFromB() from
 context
  'B'
 
  so why the special treatment for member variables, is this supposed to
 be a
  feature?
 
  -nathan

 That is OOP accross all languages.  If you want the child class to
 modify the variable, then set it to protected.  Private is only
 accessible within that class.


I know that sounds like it should make sense but if it's true, it's an
aspect I've never known about, at least maybe I'm just spacing really bad
or something...

Anyway, this chokes in javac:

public class PrivateAccess
{
private Boolean isAccessible = true;
}

class PrivateAccessChild extends PrivateAccess
{
public Boolean getAccessible()
{
return isAccessible;
}
}

PrivateAccessChild.java:5: isAccessible has private access in PrivateAccess
return isAccessible;
   ^

-nathan


Re: [PHP] Bazar behavior w/ private member variables

2012-07-12 Thread Nathan Nobbe
On Thu, Jul 12, 2012 at 9:23 PM, Nathan Nobbe quickshif...@gmail.comwrote:

 On Thu, Jul 12, 2012 at 8:38 PM, Tommy Pham tommy...@gmail.com wrote:

 On Thu, Jul 12, 2012 at 7:19 PM, Nathan Nobbe quickshif...@gmail.com
 wrote:
  Hi all,
 
  Strangely PHP seems to let each class have its own layer of private
 scope
  for member variables.  If a subclass defines a member variable of the
 same
  name as one defined in the parent the values are maintained
 independently
  in instances of the  child class.
 
  First off a simple class with a private member variable $_myPrivate,
 and a
  public accessor method which returns its value:
 
  class A
  {
  private $_myPrivate = 5;
 
  public function getMyPrivate()
  {
  return $this-_myPrivate;
  }
  }
 
 
  Second, a subclass, that gets weird right away, first we define a
 private
  member variable that already has been defined in the parent class, and
 give
  it a different initial value.  To illustrate the behavior we have two
  accessor methods, setMyPrivate that uses the $this keyword to get the
 value
  of $_myPrivate, which returns the value of the subclasse's version of
 the
  variable, and getParentsMyPrivate, that calls A::getMyPrivate via the
  parent keyword and it returns the value of $_myPrivate as defined in the
  base class.
 
  class B extends A
  {
  private $_myPrivate = 6;
 
  public function setMyPrivate()
  {
  $this-_myPrivate = 6;
  }
 
  public function getMyPrivate()
  {
  return $this-_myPrivate;
  }
 
  public function getParentsMyPrivate()
  {
  return parent::getMyPrivate();
  }
  }
 
 
  Look at a var_dump of an instance of B:
 
  object(B)#2 (2) {
[_myPrivate:B:private]=
int(6)
[_myPrivate:A:private]=
int(5)
  }
 
  clearly storage is allocated for two different values.  Now I'm sure you
  all know that if I were to define a private method in A and try to call
 it
  from B a Fatal error is raised, something on the order of
 
  PHP Fatal error:  Call to private method A::tryToCallMeFromB() from
 context
  'B'
 
  so why the special treatment for member variables, is this supposed to
 be a
  feature?
 
  -nathan

 That is OOP accross all languages.  If you want the child class to
 modify the variable, then set it to protected.  Private is only
 accessible within that class.


 I know that sounds like it should make sense but if it's true, it's an
 aspect I've never known about, at least maybe I'm just spacing really bad
 or something...

 Anyway, this chokes in javac:

 public class PrivateAccess
 {
 private Boolean isAccessible = true;
 }

 class PrivateAccessChild extends PrivateAccess
 {
 public Boolean getAccessible()
 {
 return isAccessible;
 }
 }

 PrivateAccessChild.java:5: isAccessible has private access in PrivateAccess
 return isAccessible;
^

 -nathan


Ahhh, but if I add the private declaration in the subclass it works.  Where
have I been??

-nathan


[PHP] problem loading php extension: undefined reference to __gxx_personality_v0‏

2012-05-02 Thread Nathan Ridge

Hi,
 
I'm having trouble loading a PHP extension that I made. 
When starting PHP, I get the following error:
 
PHP Warning:  PHP Startup: Unable to load dynamic library 
'/usr/lib/php5/20090626/libtg.so' - /usr/lib/php5/20090626/libtg.so: undefined 
symbol: __gxx_personality_v0 in Unknown on line 0
 
libtg.so is my extension. It is a wrapper around a C++ library, made
using SWIG (http://www.swig.org/).
 
I know __gxx_personality_v0 is a symbol from libstdc++, but my extension,
libtg.so, is linked to libstdc++. I have confirmed this using ldd:
 
$ ldd libtg.so
linux-vdso.so.1 =  (0x7fff5f932000)
libstdc++.so.6 = /usr/lib/libstdc++.so.6 (0x7f3fc937c000)
libm.so.6 = /lib/libm.so.6 (0x7f3fc90f9000)
libgcc_s.so.1 = /lib/libgcc_s.so.1 (0x7f3fc8ee2000)
libc.so.6 = /lib/libc.so.6 (0x7f3fc8b5f000)
/lib64/ld-linux-x86-64.so.2 (0x7f3fc98fc000)
 
Any ideas as to why PHP is not finding this symbol, or how I can further 
diagnose the problem?
 
Thanks,
Nate  

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



[PHP] date() confustion

2012-04-25 Thread Nathan Nobbe
Hi everyone,

Does anybody know what might influence the output of the date() function
besides date.timezone setting?

Running through some code in an app I'm working on, I have this code:

$timestamp = time();
$mysqlDatetime = date(Y-m-d G:i:s, $timestamp);

Logging these values yields:

INSERT TIMESTAMP:  1335414561
INSERT DATE TIME:  2012-04-26 4:29:21

But then from the interactive interpreter on the same box (same php.ini as
well):

php  echo date(Y-m-d G:i:s, 1335414561);
2012-04-25 22:29:21

I get this same output from another random computer of mine and I've
verified date.timezone is consistent in both environments.

Something's going on in the first case, but I'm unsure what; any ideas?

Your help appreciated as always.

-nathan


Re: [PHP] date() confustion

2012-04-25 Thread Nathan Nobbe
On Wed, Apr 25, 2012 at 10:44 PM, Simon J Welsh si...@welsh.co.nz wrote:

 On 26/04/2012, at 4:40 PM, Nathan Nobbe wrote:

  Hi everyone,
 
  Does anybody know what might influence the output of the date() function
  besides date.timezone setting?
 
  Running through some code in an app I'm working on, I have this code:
 
  $timestamp = time();
  $mysqlDatetime = date(Y-m-d G:i:s, $timestamp);
 
  Logging these values yields:
 
  INSERT TIMESTAMP:  1335414561
  INSERT DATE TIME:  2012-04-26 4:29:21
 
  But then from the interactive interpreter on the same box (same php.ini
 as
  well):
 
  php  echo date(Y-m-d G:i:s, 1335414561);
  2012-04-25 22:29:21
 
  I get this same output from another random computer of mine and I've
  verified date.timezone is consistent in both environments.
 
  Something's going on in the first case, but I'm unsure what; any ideas?
 
  Your help appreciated as always.
 
  -nathan


 A call to date_default_timezone_set() during execution can change the
 timezone. If you add echo date_default_timezone_get(); just before this,
 does it give the same output as your date.timezone setting?


Simon,

I was dumping out the value from ini_get('date.timezone'); seems it must be
getting set at runtime.

Thanks!

-nathan


[PHP] Jobs in Denver

2012-03-05 Thread Nathan Nobbe
Hey gang,

Anyone looking for solid PHP gigs in the Denver area, (or would consider
moving to Denver b/c it's so awesome!) contact me offline; I've got the
hookup!

-nathan


Re: [PHP] [php] static html search engine for php static html site

2011-12-27 Thread Nathan Nobbe
On Mon, Dec 26, 2011 at 6:17 AM, HELP LINE izod...@gmail.com wrote:

 Does any know of a better static search engine that i can integrate to my
 static php html site. it should not be Google or yahoo bing.


not sure if it's come up yet, but this might work for you,

http://www.sphider.eu/

it's based on mysql fulltext, not something i would go for, but may be
viable on your shared hosting solution.

-nathan


[PHP] Friday Distraction

2011-10-28 Thread Nathan Nobbe
Hi gang,

Thinking database i/o would be the slowest part of a request in your new zf
/ amf app?

Leave it to Zend_Amf to burn more cycles marshaling the protocol!

http://s289.photobucket.com/albums/ll238/quickshiftin/?action=viewcurrent=ScreenShot2011-10-24at74724PM.png

Happy Halloween!

-nathan


Re: [PHP] Friday Distraction

2011-10-28 Thread Nathan Nobbe
On Fri, Oct 28, 2011 at 5:23 PM, Eric Butera eric.but...@gmail.com wrote:

 On Fri, Oct 28, 2011 at 7:07 PM, Daniel Brown danbr...@php.net wrote:
  On Fri, Oct 28, 2011 at 18:36, Nathan Nobbe quickshif...@gmail.com
 wrote:
  Hi gang,
 
  Thinking database i/o would be the slowest part of a request in your new
 zf
  / amf app?
 
  Leave it to Zend_Amf to burn more cycles marshaling the protocol!
 
 
 http://s289.photobucket.com/albums/ll238/quickshiftin/?action=viewcurrent=ScreenShot2011-10-24at74724PM.png
 
 Ends up looking startlingly like the original Sim City.
 
  --
  /Daniel P. Brown
  Network Infrastructure Manager
  http://www.php.net/
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 

 kcachegrind is great.

 SimCity is great!  Just the other day I was thinking about that
 soundtrack it played over the PC speaker, hilarious.


Agreed, the only thing that isn't great in this context .. Zend_Amf, haha!

-nathan


Re: [PHP] Friday Distraction

2011-10-28 Thread Nathan Nobbe
On Fri, Oct 28, 2011 at 5:26 PM, Eric Butera eric.but...@gmail.com wrote:

 On Fri, Oct 28, 2011 at 7:24 PM, Nathan Nobbe quickshif...@gmail.com
 wrote:
 
 
  On Fri, Oct 28, 2011 at 5:23 PM, Eric Butera eric.but...@gmail.com
 wrote:
 
  On Fri, Oct 28, 2011 at 7:07 PM, Daniel Brown danbr...@php.net wrote:
   On Fri, Oct 28, 2011 at 18:36, Nathan Nobbe quickshif...@gmail.com
   wrote:
   Hi gang,
  
   Thinking database i/o would be the slowest part of a request in your
   new zf
   / amf app?
  
   Leave it to Zend_Amf to burn more cycles marshaling the protocol!
  
  
  
 http://s289.photobucket.com/albums/ll238/quickshiftin/?action=viewcurrent=ScreenShot2011-10-24at74724PM.png
  
  Ends up looking startlingly like the original Sim City.
  
   --
   /Daniel P. Brown
   Network Infrastructure Manager
   http://www.php.net/
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
  
  
 
  kcachegrind is great.
 
  SimCity is great!  Just the other day I was thinking about that
  soundtrack it played over the PC speaker, hilarious.
 
  Agreed, the only thing that isn't great in this context .. Zend_Amf,
 haha!
  -nathan
 

 I saw your post on that the other day - looks like there's a native
 php extension you might look into.  The author was quite proud of the
 hasty response it was capable of, going as far as to say his library
 was faster than flash can decode it.


Yeah, I got it built under php 5.3, it rips.

Funny thing is amfphp has a userpace  serializer of it's own and it of
course takes less time than db i/o.

Dropping in the extension takes the time spent serializing down to
practically nothing.

Suffice it to say we'll be migrating to the extension on subsequent revision
of the project I alluded to.

Also, the more I use zf, the less I like, lol.  Look at this line from the
documentation - Fools!

Zend_Server_Interface provides an interface that mimics PHP 5's
SoapServer class;
all server classes should implement this interface in order to provide a
standard server API.

-nathan


Re: [PHP] Exporting large data from mysql to html using php

2011-10-27 Thread Nathan Nobbe
On Mon, Oct 24, 2011 at 6:50 PM, Jason Pruim li...@pruimphotography.comwrote:

 Now that I've managed to list 3 separate programming languages and somewhat
 tie it back into php here's the question...

 I have about 89 million records in mysql... the initial load of the page
 takes 2 to 3 minutes, I am using pagination, so I have LIMIT's on the SQL
 query's... But they just aren't going fast enough...

 What I would like to do, is pull the data out of MySQL and store it in the
 HTML files, and then update the HTML files once a day/week/month... I can
 figure most of it out... BUT... How do I automatically link to the
 individual pages?

 I have the site working when you pull it from MySQL... Just the load time
 sucks... Any suggestions on where I can pull some more info from? :)

 Thanks in advance!


dial in the db schema (think keys) and queries; then investigate a reverse
proxy like varnish to cache the generated html.

you'll be able to handle a couple thousand requests per second against the
proxy in no time.

might be worth pre-generating some of the pages if they are still really
slow after db optimization.

-nathan


Re: [PHP] Friday Distraction

2011-10-21 Thread Nathan Nobbe
nice one!

On Fri, Oct 21, 2011 at 10:27 AM, Daniel Brown danbr...@php.net wrote:

I'll get this week's Friday distraction kicked off here with
 something shared with me by a Facebook friend.  If you're on Facebook,
 try this.  It's pretty sweet (and safe for work and kids).

http://www.takethislollipop.com/

 --
 /Daniel P. Brown
 Network Infrastructure Manager
 http://www.php.net/

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




Re: [PHP] Friday Distraction

2011-10-21 Thread Nathan Nobbe
Friday :P

On Fri, Oct 21, 2011 at 10:35 AM, Daniel Brown danbr...@php.net wrote:

 On Fri, Oct 21, 2011 at 12:34, Nathan Nobbe quickshif...@gmail.com
 wrote:
  nice one!

Quit top-posting!  ;-P

 --
 /Daniel P. Brown
 Network Infrastructure Manager
 http://www.php.net/



Re: [PHP] Friday Distraction

2011-10-21 Thread Nathan Nobbe
On Fri, Oct 21, 2011 at 11:38 AM, Tedd Sperling tedd.sperl...@gmail.comwrote:

 On Oct 21, 2011, at 12:27 PM, Daniel Brown wrote:

 I'll get this week's Friday distraction kicked off here with
  something shared with me by a Facebook friend.  If you're on Facebook,
  try this.  It's pretty sweet (and safe for work and kids).
 
 http://www.takethislollipop.com/
 
  --
  /Daniel P. Brown

 Not meaning to be ignorant, but why?

 What's the point here?

 I have grandkids and about a dozen other species of relatives/friends
 trying to get me to do stuff (i.e., like/friend/post/reply/accept) on
 FaceBook et al, but I don't see the point. It looks like a total waste of
 time. Why should I care if someone post something on their FaceBook account?
 I would rather spend my time programming, teaching programming, and reading
 about programming.

 Maybe I'm just getting too old for this stuff.

 Cheers,

 tedd


tedd, even older folks are getting on there these days.  sure there are lame
aspects as there are w/ just about anything; but it is a nice way to stay in
touch w/ folks youd probly otherwise have lost touch w/.  my 2c.

-nathan


Re: [PHP] Re: Repetitive answers . . .

2011-09-15 Thread Nathan Nobbe
On Wed, Sep 14, 2011 at 10:06 PM, Joshua Stoutenburg
jehoshu...@gmail.comwrote:

 On Wed, Sep 14, 2011 at 11:59 AM, Govinda govinda.webdnat...@gmail.com
 wrote:
  As for duplicate answers...,
 
  [snip]
 
 
  Also newbies may tend to like the multiples answers.. for the different
 perspectives, as Dan said, but also when they are exact dupe answers -
 because then the newbie knows the answer is definitive.. and then stops
 asking the list.. and starts doing what work is called for.
 
  -Govinda
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 

 That's a good point.  The absence of objection to a provided answer
 doesn't necessarily make it definitive since it could just be the
 masses passed over the conversation.  Therefore, yes, duplicate
 answers are a good thing.

 Thanks everybody for your patience in helping this mailing list
 newcomer understand how things work.

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


wait, it sounds like we could use another answer .., yes ppl like to answer
things many times here, often with almost identical suggestions, and many
spins on how to approach the problem, including alternative perspectives on
life..; the ebb--flow of php-general ;)

-nathan


[PHP] Installer for 5.3 on Windows ?

2011-08-23 Thread Nathan Nobbe
Hey gang,

Wondering where the installer for php 5.3 on Windows is?

Not seeing it here:

http://windows.php.net/download/

Any clues appreciated,

-nathan


[PHP] Re: Installer for 5.3 on Windows ?

2011-08-23 Thread Nathan Nobbe
On Tue, Aug 23, 2011 at 4:06 PM, Nathan Nobbe quickshif...@gmail.comwrote:

 Hey gang,

 Wondering where the installer for php 5.3 on Windows is?

 Not seeing it here:

 http://windows.php.net/download/

 Any clues appreciated,

 -nathan


Hmm,

I have found some .msi files on this page:

http://windows.php.net/downloads/releases/archives/

still wondering why there is no link on the main download page..

-nathan


Re: [PHP] Doctrine madness!

2011-06-20 Thread Nathan Nobbe
On Mon, Jun 20, 2011 at 5:16 AM, Ford, Mike m.f...@leedsmet.ac.uk wrote:

  -Original Message-
  From: Nathan Nobbe [mailto:quickshif...@gmail.com]
  Sent: 16 June 2011 17:51

 [...]

  Here's what's going on, I instantiate a model object for the product
  table
  from my application
 
  $newRecord = new Product();
 
  at this point memory usage goes up noticeably.  I don't really care
  though
  because I figure I can delete it, but look at this madness I have
  going
  (which *fails* to free up the memory)
 
  $newRecord-clearRelated();
  $newRecord-free();
  unset($newRecord);
  gc_collect_cycles();
 
  after all of this memory consumption is still dramatically higher
  than prior
  to the first call creating the object above.  This I've verified
  through
  memory_get_usage().
 
  here's the output from the memory_get_usage() calls
 
  int(166461440) // before new Product()
  int(169345024) // directly after new Product()
  int(169345024) // after madness trying to free memory used by new
  Product()

 I know nothing about Doctrine, but after all the unrelated
 discussion and your renewed plea for someone to address the issue,
 I decided to write conduct some simple tests.

 So I wrote a very simple class that basically just hogs some memory
 when instantiated, and tried some simple instantiations and
 releases.

 At each stage, I measured current and peak memory usage, and the
 results were:

  Initial
Usage = 262,144
Peak  = 262,144

  After single instantiation ($a = new Hog();)
Usage = 3,932,160
Peak  = 3,932,160

  After resetting that to NULL ($a = NULL;)
Usage = 524,288
Peak  = 3,932,160

  After second single instantiation ($b = new Hog();)
Usage = 3,932,160
Peak  = 3,932,160

  After instantiating 3 more
Usage = 15,728,640
Peak  = 15,728,640

  After resetting all those to NULL
Usage = 1,310,720
Peak  = 15,728,640

  After 4 instantiations again
Usage = 15,728,640
Peak  = 15,728,640

 This seems to be pretty much what I (and you!) would expect,
 indicating that the memory used by objects can be recovered by PHP
 when the object is released. This being the case, I would suggest
 that something in your script is not freeing things up the way it
 should, the prime candidate being the clearRelated() method. Either
 that, or you have circular references that the gc_collect_cycles()
 function is unable to recover. But, bottom line, I'd say you're
 right that it's probably a Doctrine-related issue as the underlying
 PHP functionality seems to work reasonably well.


Mike, thanks for your time here.  I have been able to develop a workaround
and it actually does run fast enough to work for now.  Actually, I'd love to
pin down the issue w/ Doctrine, I just have a lot of clients right now and
can't justify the time, so the hacky solution will have to suffice.

I did just find a bug in PHPUnit about a week ago, but that was easy to
isolate.  In order to isolate the issue with Doctrine it will take me a few
hours.  So even though today is a rainy one, I won't be able to work on it
because I have too much other stuff going on that actually pays the bills,
lol.

-nathan


Re: [PHP] Doctrine madness!

2011-06-18 Thread Nathan Nobbe
On Fri, Jun 17, 2011 at 1:19 PM, Jim Lucas li...@cmsws.com wrote:

 On 6/16/2011 3:15 PM, Nathan Nobbe wrote:
  what it really amounts to is php is good at doing 1 thing and 1 thing
 only,
  generating web pages.  for anything else, including command line scripts
  that run for more than 30 seconds, choose an actual programming language
 or
  be prepared to deal w/ hacky, disgusting workarounds.
 

 Nathan,

 I would have to disagree with your statement about using PHP for
 applications
 that take more then 30 seconds or CLI scripts.

 I have a daemon (read: scripts) that I wrote using PHP.  It listens on a
 few UDP
 sockets and maintains an open connection to mysql.  It receives server
 updates
 and other client requests for data.  When it receives a client update it
 updates
 a couple tables in mysql.  When it receives a request from a server for
 data, it
 goes to mysql gets all needed data, compiles it into the format requested
 and
 sends it down the wire.

 This daemon starts when my system starts up.  As of this morning it has
 been
 running non stop since Feb 28th (about 108 days).  Between then and now it
 has
 received over 35M server updates and over 1.8M client requests.  I think it
 gets
 used a bit.

 So, to say that doing anything with PHP that takes longer then 30 seconds
 to
 complete will require you to use hacky and disgusting workarounds is false.

 I have no hacks nor disgusting workarounds in my scripts.  Combined the
 scripts
 total about 200 lines, over half of which is either comments or vertical
 white
 space.

 It has been running pretty much non-stop since August 2007 with minimal
 maintenance needed.


Jim,

thanks for your response.  This was an exaggeration based on my frustration
with this issue.  i've written long running php scripts before, but in
general my experience is long running scripts and daemons are second
class citizens for php by design.

and in fact i do need to employ a hacky workaround in this situation.  and
also no one has addressed my actual question!  the thread turned into a
debate about the merit of frameworks, which i simply dont have time to
engage in.  threads like this are the reason i hardly contribute to the list
anymore.

if youd like to help me determine what the non-disgusting workaround in this
case is, that would be awesome.  but until im to the bottom of the real
issue, ill maintain some distain for cli / daemon scripts in php.

-nathan


[PHP] Doctrine madness!

2011-06-16 Thread Nathan Nobbe
Hi gang,

If anyone out there has some experience w/ Doctrine now would be a great
time to share it!

So I'm writing a batch importer and noticed memory usage climbing during
script execution.

In the debugging effort I've isolated it down to a Doctrine issue.

Here's what's going on, I instantiate a model object for the product table
from my application

$newRecord = new Product();

at this point memory usage goes up noticeably.  I don't really care though
because I figure I can delete it, but look at this madness I have going
(which *fails* to free up the memory)

$newRecord-clearRelated();
$newRecord-free();
unset($newRecord);
gc_collect_cycles();

after all of this memory consumption is still dramatically higher than prior
to the first call creating the object above.  This I've verified through
memory_get_usage().

here's the output from the memory_get_usage() calls

int(166461440) // before new Product()
int(169345024) // directly after new Product()
int(169345024) // after madness trying to free memory used by new Product()

I've also tried an explicit call to the destructor of $newRecord, but that
results in a fatal attempting to call an unknown method.

Any help would be greatly appreciated as google hasn't been able to point me
to the answer thus far.

thx,

-nathan


Re: [PHP] Doctrine madness!

2011-06-16 Thread Nathan Nobbe
On Thu, Jun 16, 2011 at 1:58 PM, Eric Butera eric.but...@gmail.com wrote:

 On Thu, Jun 16, 2011 at 12:51 PM, Nathan Nobbe quickshif...@gmail.com
 wrote:
  Hi gang,
 
  If anyone out there has some experience w/ Doctrine now would be a great
  time to share it!
 
  So I'm writing a batch importer and noticed memory usage climbing during
  script execution.
 
  In the debugging effort I've isolated it down to a Doctrine issue.
 
  Here's what's going on, I instantiate a model object for the product
 table
  from my application
 
  $newRecord = new Product();
 
  at this point memory usage goes up noticeably.  I don't really care
 though
  because I figure I can delete it, but look at this madness I have going
  (which *fails* to free up the memory)
 
  $newRecord-clearRelated();
  $newRecord-free();
  unset($newRecord);
  gc_collect_cycles();
 
  after all of this memory consumption is still dramatically higher than
 prior
  to the first call creating the object above.  This I've verified through
  memory_get_usage().
 
  here's the output from the memory_get_usage() calls
 
  int(166461440) // before new Product()
  int(169345024) // directly after new Product()
  int(169345024) // after madness trying to free memory used by new
 Product()
 
  I've also tried an explicit call to the destructor of $newRecord, but
 that
  results in a fatal attempting to call an unknown method.
 
  Any help would be greatly appreciated as google hasn't been able to point
 me
  to the answer thus far.
 
  thx,
 
  -nathan
 

 This might help

 http://php.net/manual/en/features.gc.collecting-cycles.php



Thanks for the reply Eric.

Sadly this is of no avail.  For php 5.2 doctrine has a free() method on
several of its classes which breaks the circular references, allowing the
garbage collector to clean things up in that environment.  Allegedly this
isn't needed in 5.3 due to the link you've shared, however, I'm using the
free() call on the $newRecord variable just for grins in a 5.3 environment.

I'm also calling gc_collect_cycles() to try and force a gc, however that
seems to have no effect.

Guess what the folks on doctrine irc channel have suggested .. upgrading to
version 2 or a hacky workaround (basically working on smaller units and
letting the script complete for these smaller chunks of input data).
 Rather disappointing if you ask me.

At this point I'm about as disappointed in php as I am doctine, one would
think there's a way to reclaim this memory, but I can't find a way short of
terminating the script :(

-nathan


Re: [PHP] Doctrine madness!

2011-06-16 Thread Nathan Nobbe
On Thu, Jun 16, 2011 at 3:58 PM, Eric Butera eric.but...@gmail.com wrote:

 On Thu, Jun 16, 2011 at 5:37 PM, Daevid Vincent dae...@daevid.com wrote:
  -Original Message-
  From: Nathan Nobbe [mailto:quickshif...@gmail.com]
  Sent: Thursday, June 16, 2011 9:51 AM
  To: php-general@lists.php.net
  Subject: [PHP] Doctrine madness!
 
  Hi gang,
 
  If anyone out there has some experience w/ Doctrine now would be a great
  time to share it!
 
  Yeah, I've used Doctrine as part of Symfony. Both suck balls and are a
 perfect example of why you should NEVER use frameworks. Lesson learned the
 hard way. Re-write with your own MySQL wrappers and for the love of God and
 all that is holy do NOT make it an ORM wrapper.


some of the functionality doctrine has is amazing and it is a big time saver
for sure.  sf is also one of the smoothest frameworks ive used in php.  i
think this goes to show you that frameworks don't to *everything* perfectly,
nor can they.

what i find more painful is the fact that 130+ ppl on the doctrine irc
channel can't offer anything but a shoddy workaround that they assume i'm
too dumb to have already thought of myself.  when in reality, it's like 'no,
your crappy library has a bug in it, could you please address that...'

what is even more disheartening is that through php itself, i have no way of
deciphering which variable is holding this memory or any way to go about
freeing it, even with the magic circular reference handling of 5.3.  that
bodes badly for php, plain and simple.

what it really amounts to is php is good at doing 1 thing and 1 thing only,
generating web pages.  for anything else, including command line scripts
that run for more than 30 seconds, choose an actual programming language or
be prepared to deal w/ hacky, disgusting workarounds.

-nathan


RE: [PHP] Doctrine madness!

2011-06-16 Thread Nathan Nobbe
On Jun 16, 2011 5:31 PM, Daevid Vincent dae...@daevid.com wrote:



  -Original Message-
  From: Eric Butera [mailto:eric.but...@gmail.com]
  Sent: Thursday, June 16, 2011 2:58 PM
  To: Daevid Vincent
  Cc: php-general@lists.php.net
  Subject: Re: [PHP] Doctrine madness!
 
  On Thu, Jun 16, 2011 at 5:37 PM, Daevid Vincent dae...@daevid.com
wrote:
   -Original Message-
   From: Nathan Nobbe [mailto:quickshif...@gmail.com]
   Sent: Thursday, June 16, 2011 9:51 AM
   To: php-general@lists.php.net
   Subject: [PHP] Doctrine madness!
  
   Hi gang,
  
   If anyone out there has some experience w/ Doctrine now would be a
great
   time to share it!
  
   Yeah, I've used Doctrine as part of Symfony. Both suck balls and are a
  perfect example of why you should NEVER use frameworks. Lesson learned
the
  hard way. Re-write with your own MySQL wrappers and for the love of God
and
  all that is holy do NOT make it an ORM wrapper.
  
   KTHXBYE.
  
 
  I do believe that was the most eloquent and enlightened email that has
  ever graced my inbox.  Thank you for taking the time to edify us with
  that pithy reply.

 Glad I could be of service. There was no point in elaborating more on
either Doctrine or Symfony any further.

You've been even less helpful than the broken community surrounding
doctrine.  Thanks for your effort daevid, I know you tried hard ;)

-nathan


Re: [PHP] Doctrine madness!

2011-06-16 Thread Nathan Nobbe
On Jun 16, 2011 6:53 PM, Eric Butera eric.but...@gmail.com wrote:

 On Thu, Jun 16, 2011 at 7:32 PM, Daevid Vincent dae...@daevid.com wrote:
 
 
  -Original Message-
  From: Eric Butera [mailto:eric.but...@gmail.com]
  Sent: Thursday, June 16, 2011 2:58 PM
  To: Daevid Vincent
  Cc: php-general@lists.php.net
  Subject: Re: [PHP] Doctrine madness!
 
  On Thu, Jun 16, 2011 at 5:37 PM, Daevid Vincent dae...@daevid.com
wrote:
   -Original Message-
   From: Nathan Nobbe [mailto:quickshif...@gmail.com]
   Sent: Thursday, June 16, 2011 9:51 AM
   To: php-general@lists.php.net
   Subject: [PHP] Doctrine madness!
  
   Hi gang,
  
   If anyone out there has some experience w/ Doctrine now would be a
great
   time to share it!
  
   Yeah, I've used Doctrine as part of Symfony. Both suck balls and are
a
  perfect example of why you should NEVER use frameworks. Lesson learned
the
  hard way. Re-write with your own MySQL wrappers and for the love of God
and
  all that is holy do NOT make it an ORM wrapper.
  
   KTHXBYE.
  
 
  I do believe that was the most eloquent and enlightened email that has
  ever graced my inbox.  Thank you for taking the time to edify us with
  that pithy reply.
 
  Glad I could be of service. There was no point in elaborating more on
either Doctrine or Symfony any further.
 
  Sometimes, like that guy that fell down the canyon, you have to cut your
own arm off with a swiss army knife to save your life. In this case, get rid
of Doctrine or any other ORM, despite the painful operation, and save your
project from a slow and agonizing death.
 
  ORM's and ActiveRecord style wrappers, while sounding sexy -- like the
babe on the other end of a 1-900 number -- usually turn out to be fat and
bloated. All that magic comes at a price. This is why Ruby on Rails has
started to fall out of favor with ANY big shop and you are hearing less and
less about it. It's cute and seems magnificent at first, but quickly starts
to show its limitations and short-comings when you REALLY try to use it.
 
  :)
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 

 I'm sorry but this is absolute rubbish.  I used to write my queries by
 hand, but over time you start to realize that perhaps, maybe writing
 out thousands of identical lines of code over hundreds of projects
 might not be an efficient usage of time.  If you have performant
 requirements, that is one thing and can easily be overcome with slight
 deviations on a case by case basis.  Most of the time, contrary to
 your position, things just need to work and be completed quickly.
 What is the more common question from clients: why is this so slow,
 or, client asks why is this not finished yet?

 I do like the half-hearted diatribe against ROR, which I will assume
 is a wildcard, allow any language/framework combination to stand-in.
 The real take-away message here is that you're trying to paint
 everything with the brush that you see the world in, while the reality
 is that not everyone has your requirements.  Personally, I don't enjoy
 trying to mess around with ill-conceived, backwards-compatible
 adhering designs from 12 years ago.  I understand that growth is
 organic and deal with it on a daily basis in my own projects.  Hence,
 I use a framework and other tooling that allows me to complete jobs in
 a tidy and orderly fashion.  If I need something a little more
 cutting-edge I can always drop down lower on the stack to bypass PHP
 with other techniques like caching or bypassing the framework
 altogether.  To say that all frameworks are a complete waste of time
 and will only (absolutely) end in failure is quite a disservice to
 anyone who reads this list.

 I've seen too many people over the years try and rally against common
 sense practices like using prepared statements for perhaps a marginal
 gain of performance on one page while their load averages are 0,0,0.
 One archived post could be the cause of 50 hacked websites.  This is
 not the position people - or, mentors, if you will - should be taking.
  Same with other tools that allow developers to crank out projects
 orders faster.

 This post isn't meant to be some vitriol inspired rant, but rather a
 sincere wake-up.  Imagine the intended audience of php-general and ask
 yourself if you're doing harm.  An example:  when I say harm, every
 other framework I have seen from php (ok, ok, ZF makes you call
 escape), ruby, python, and node all escape variables in
 templates/views by default.  PHP is the only one that lets you echo
 out XSS out of the box.  Of course, with diligence and time we can all
 overcome these things, but that does not mean someone with the
 ambition to bang together a quick website for a relative understands
 the real perils they're getting into - I certainly did not.  Now I
 wonder how calamity did not destroy everything in my beginnings.
 Times have changed since then and our sites are under constant

Re: [PHP] phpsadness

2011-05-28 Thread Nathan Nobbe
On Sat, May 28, 2011 at 4:33 AM, Robert Cummings rob...@interjinn.comwrote:

 On 11-05-28 05:26 AM, Andre Polykanine wrote:

 Hello Lester,

 Actually,  many of the points are not important for me so far, however
 this one really drives me mad:
 http://phpsadness.com/?page=sad/35   (can't   explode()  by  an  empty
 string)
 Besides that, he says nothing about unicode issues.
 I  love  PHP  (I  really do, it's a neat language, as for me!), but it
 *should* be unicode by default. If you ever read my code when I try to
 make and strtr() with a unicode string, you'll understand me because I
 do  an iconv(), then strtr() and then an iconv() back to unicode. That
 is not a good coding practice, is it?


 Isn't explode() with an empty string akin to division by zero?


Strings are already accessible through array notation anyway, seems like ol
dude may benefit from a php-general membership as well.

-nathan


Re: [PHP] phpsadness

2011-05-28 Thread Nathan Nobbe
On Sat, May 28, 2011 at 1:34 PM, Andre Polykanine an...@oire.org wrote:

 Hello Nathan,

 Do you mean $x{8}?


yup, that or $x[8];


 That is good but not for all situations.
 I  need sometimes to make an array with letters as keys and numbers as
 values,  like  this  (I  give  English alphabet just as an example, so
 please don't suggest str_split):
 $alphabet=abcdefghijklmnopqrstuvwxyz;


this just looks like you're after a quick way to populate an array.


 // I wish that worked
 $alphabet_array=explode('', $alphabet);
 $letter_numbers=array_flip($alphabet_array);


do you remember what you needed it for?  w/ the array access notation you
can get at any letter by index or you can get any index by letter.

$alphabet=abcdefghijklmnopqrstuvwxyz;

echo $alphabet[1]; // b
echo strpos($alphabet, 'b'); // 1


 this is just one case I encountered some time ago. Yes, I made this by
 separating  letters with commas... but it's not the unique case when I
 need it.


It would be nice to hear what the use-case is for this issue.

-nathan


Re: [PHP] What's up with Quercus?

2011-05-28 Thread Nathan Nobbe
On Fri, May 27, 2011 at 11:52 PM, Arnold Hesnod ahes...@mindvox.com wrote:

 Although I've been mostly using Java and Ruby in my professional software
 development work for the past decade or so, in the past two or three years
 I've started to do more and more PHP.  I originally started using PHP
 because I needed to set-up and customize Drupal for a project.  Although as
 a programmer I've come to feel comfortable writing PHP code, I still don't
 feel like I have a good sense of where PHP is going as a platform and what's
 it's future is.  As the Drupal site has continued to grow both in terms of
 features and usage, it's become clear that this is something that I need to
 research and educate myself about.

 That led me to give a closer look at Quercus, the implementation of PHP 5
 that runs on top of the JVM.  I'd already heard about it somewhere along the
 line, but it's only in the past couple of weeks that I've actually pulled it
 down, read through the documentation and some of the source and tried it
 out.  So far I'm pretty impressed and enthusiastic about it.  The
 cancellation of PHP 6 combined with the steady trickle of PHP-related bugs
 and security vulnerabilities that have become public over the past few years
 had made me very nervous about the future of the platform.  Having an
 open-source implementation of PHP that runs on the JVM, which is like the
 gold standard for server application performance and reliability, is
 reassuring.  The fact that it makes it easy and fast to use the huge library
 of Java frameworks out there in your PHP applications doesn't hurt either.


first off quercus is not 'the' implementation of php running on the jvm,
it's 'an' implementation.  ibm project 0 is another

http://www.projectzero.org/

and there may be more.  also, java is fast, but php applications can be made
fast as well, when it comes to serving web pages.  there are times when i
would consider implementing some domain logic in something like java for
speed, but for delivering applications on the web, php is very useful and
practical in terms of performance.


 Although I've had great results so far in my experiments with Quercus, I'm
 curious to hear about other PHP developers' experiences with it.  Even
 though it seems like a significant number of people are using it for
 production applications, I'm curious why it's adoption isn't even higher
 than it is?  Given the difficulties of writing a Virtual Machine, it seems
 like leveraging the JVM is a no brainer.  Is there some technical drawback
 that I'm unaware of or is it just a case of inertia?


a lot of projects are mating their favorite language w/ the jvm which does
seem like a great idea, but one of the main drawbacks is the pace of feature
additions w/ the 'real' version of the project.  when i looked into quercus
a few years ago there wasn't support for things like spl and i'm not sure
where they stand w/ 5.3 features like closures and namespaces. not only that
but on any given minor release of php where is the parallel from quercus.
 also, the professional version of resin costs money.

these are probly the main reasons why the resin community isn't blowing up.

-nathan


Re: [PHP] phpsadness

2011-05-27 Thread Nathan Nobbe
On Fri, May 27, 2011 at 3:52 PM, Robert Cummings rob...@interjinn.comwrote:

 On 11-05-27 03:52 PM, Daevid Vincent wrote:

 A friend sent me this URL today. While amusing, he's got many valid points
 and I certainly share in his frustration.

 http://www.phpsadness.com


 What a whiner!

 Many of the things listed are things which give PHP character and history.


Too bad it's not a blog post with a comments section.

I'd point him to the internals list :)

-nathan


Re: [PHP] semaphore release before acquire warning

2011-05-02 Thread Nathan Nobbe
On Mon, May 2, 2011 at 2:57 PM, Jeremy Greene jer...@zeevee.com wrote:

 Hi,



 I am getting a warning when calling sem_release() before (the same php
 script) calls sem_acquire(). I am doing this because it's a signal to
 another process. The other process (which happens to be C program) has
 done, or will do, a semop() to acquire the semaphore/signal. The actual
 data transfer is through shared memory.



 It does all functionally work quite nicely, but given that I'm getting
 the warning and that there doesn't seem to be any discussion of this at
 least in this list's archive maybe I'm putting a square peg into a round
 hole... or at least there's a rounder peg available.



 I did look into disabling the warning, but that got me more concerned
 since it seemed like a frowned upon thing to do and even more of a
 performance hit.



 The irony is that I'm using shared memory (and signals) exactly for
 performance reasons L


perhaps try pcntl_signal() to signal the c program rather than
sem_release().

-nathan


[PHP] Re: dynamic copyright in page footer?

2011-04-30 Thread Nathan Rixham

David Mehler wrote:

Hello,

I am trying to use php to put a copyright notice in a page footer. I'm
using the date function with the Y value for the year. Here's the
code:

?php
echo date ('Y');
?


echo implode(,, range(2011,date(Y)));

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



Re: [PHP] Flattery will get you nowhere

2011-04-28 Thread Nathan Rixham

tedd wrote:

At 4:58 PM -0400 4/27/11, Robert Cummings wrote:

Tedd who?

;)

Cheers,
Rob.


Rob what?

;-)

Cheers,

tedd



flirting?

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



Re: [PHP] JavaScript Injection ???

2011-04-25 Thread Nathan Rixham

Stuart Dallas wrote:
On Monday, 18 April 2011 at 20:50, tedd wrote: 

The form as-is produced a javascript alert() and now it doesn't.


This is not a browser change because it's happening before the browser sees the 
response (try it with curl).


It is the browser, chrome will prevent execution because the code was 
sent in the request, just check the javascript console and you'll see 
something like:


  Refused to execute a JavaScript script. Source code of script found 
within request.


Best,

Nathan


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



Re: [PHP] str_replace

2011-04-25 Thread Nathan Rixham

Jim Lucas wrote:

On 4/24/2011 8:44 AM, Ron Piggott wrote:

I am trying to figure out a syntax that will replace each instance of % with a
different letter chosen randomly from the string $puzzle_filler. $puzzle_filler
is populated with the letters of the alphabet, roughly in the same ratio as they
are used.

This syntax replaces each instance of % with the same letter:

$puzzle[$i] = str_replace ( % , ( substr ( $puzzle_filler , rand(1,98) , 1 ) )
, $puzzle[$i] );

Turning this:

%ECARBME%TIPLUP%%%E%%

Into:

uECARBMEuTIPLUPuuuEuu

Is there a way to tweak my str_replace so it will only do 1 % at a time, so a
different replacement letter is selected?

This is the syntax specific to choosing a replacement letter at random:

substr ( $puzzle_filler , rand(1,98) , 1 );

Thanks for your help.

Ron

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info



How about something simple like this?

?php

$input = '%ECARBME%TIPLUP%%%E%%';

$random_chars = range('a', 'z');

echo 'Before: '.$input.PHP_EOL;

while ( ($pos = strpos($input, '%') ) !== false )
$input[$pos] = $random_chars[array_rand($random_chars)];

echo 'After: '.$input.PHP_EOL;


just for fun

$a = '%ECARBME%TIPLUP%%%E%%';
$b = 'abcdefghijklmnobqrstuvwxyz';
echo preg_replace('/%/e','substr(str_shuffle($b),-1)', $a );

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



Re: [PHP] $_POST vars

2011-04-14 Thread Nathan Nobbe
On Wed, Apr 13, 2011 at 3:30 PM, Stuart Dallas stu...@3ft9.com wrote:

 On Wednesday, 13 April 2011 at 19:47, Nathan Nobbe wrote:
  On Wed, Apr 13, 2011 at 12:34 PM, Stuart Dallas stu...@3ft9.com wrote:
   On Wednesday, 13 April 2011 at 19:15, Nathan Nobbe wrote:
On Wed, Apr 13, 2011 at 12:04 PM, Stuart Dallas stu...@3ft9.com
 wrote:
 On Wednesday, 13 April 2011 at 18:55, Nathan Nobbe wrote:
 On Wed, Apr 13, 2011 at 11:49 AM, Jim Giner 
 jim.gi...@albanyhandball.comwrote:
 
   Can one create a set of $_POST vars within a script or is that
 not do-able?
   My display portion of my script utilizes the POST array to
 supply values to
   my input screen - this works well for the first display of an
 empty screen,
   and any following re-displays if there's an error in the user's
 input. But
   I want to use this same script/screen to display the results of
 a query
   when
   the user wants to update an existing record.
 
 
  While a user script can populate $_POST this is generally
 prohibited as it's
  typically populated by the environment.
 
  It would probly be cleaner to have the display portion of your
 script read
  from an arbitrary array.
 
  Said arbitrary array could be populated by $_POST in one case and
 the
  results of a query in another case.

 While I don't necessarily disagree with you as far as abstracting
 the source of data goes, but it's never prohibited, it just considered bad
 practice.
   
considered a bad practice means prohibited for most groups ive worked
 with.
  
   This isn't any of the groups you've worked with, this is the wide world
 and it's full of possibilities.
 
  lol youre right, and none of the groups ive worked with have been part of
 this global community, so these must be strictly new possibilities we're
 discussing on this thread...

 I clearly didn't put my point across well enough, which was that what is
 and what isn't best practice is not set in stone. Best practices vary from
 group to group and from project to project, and that's the way it should be.
 However, just because you've mostly worked in groups where this is bad
 practice does not make it bad practice.


The irony here is I've developed this rule of thumb by working with groups
that don't consider it a bad practice but should have.


Personally I've never understood this thou shalt protect the
 superglobals attitude. They're arrays, nothing more, use them in whatever
 way you want to. They're not sacred, endangered or likely to be overcome
 with the urge to kill you if you modify them. If your code changes its
 behaviour depending upon whether the data you're dealing with has come from
 within or without your code I think you have bigger style issues to address.
the reason it's a bad practice is it undermines an assumption that
 $_POST is only being populated by the environment, which in the case of
 $_POST is coming from a form field, ajax / curl request etc. as soon as that
 assumption is thrown out the window debugging becomes more involved trying
 to track down the mysterious appearance of a $_POST var. if you really need
 to store arbitrary data in a supergloabal $GLOABALS is there for that; def
 don't stuff these into $_POST :)
  
   My idea of best practice says that data coming in from outside your
 code should only ever be dealt with in the first script the request hits, so
 you should never be hunting for where an errant value in $_POST came from.
 Given this (and noting the fact that this was your suggestion to the OP)
 you're creating the problem you're trying to avoid by using an arbitrary
 array in the place of $_POST.
  well when you build programs that are more than one script in length
 you'll find that data submitted by the user is often referenced further in
 the flow than the entry script.. read: front controller. and im not creating
 a problem, im avoiding a problem by not overloading the intended use of the
 $_POST array.

 Good at making assumptions, aren't you?!


lol, i figured id give it a shot.

Anyway, again, you seem to have missed my point. In a front controller
 architecture, in my opinion, no code beyond that front controller should
 ever be referencing the get, post or cookie superglobals, and ideally not
 the server superglobal either.


I see what you're saying, but then you're implying that it's ideal to copy
the values into secondary data structure(s), perhaps modifying the values
along the way or at least have them accessed indirectly after the initial
processing.


 This, to me, is the equivalent of having all variables a system uses as
 globals which, I hope you'll agree, is something everyone agrees to be bad
 practice.


is that written in stone?

The arbitrary array i spoke of in my initial post was misleading.  I advised
it because there are two sources of data going into the same template.
 Having an abstraction for the template allows assumptions

Re: [PHP] $_POST vars

2011-04-14 Thread Nathan Nobbe
On Thu, Apr 14, 2011 at 2:53 AM, Stuart Dallas stu...@3ft9.com wrote:

 On Thursday, 14 April 2011 at 07:11, Nathan Nobbe wrote:
 On Wed, Apr 13, 2011 at 3:30 PM, Stuart Dallas stu...@3ft9.com wrote:
   On Wednesday, 13 April 2011 at 19:47, Nathan Nobbe wrote:
   I never make any assumptions about the source of any data when I'm
 developing software, whether in PHP or not. Returning to a previous point,
 usage of global variables as the source of data anywhere other than the
 initial script a request hits is tantamount to negligence. But that's just
 my opinion.
  Who said you should make assumptions. One thing you know is that $_POST
 was populated by the contents of HTTP POST, or most of it anyways, lol.

 Again, I don't see how that knowledge is useful?


you know what doesn't belong there.


   Here's an example, suppose you have an object, any object in php should
 let you dynamically create a public member variable on it on the fly unless
 there's an explicit override in __get().
 
  $oXml = new
 SimpleXmlElement('vendor-datacontentreal-data/content/vendor-data');
 
  now someone decides to use it to store something clever, because they
 can, and it's so much easier than creating an appropriate location
 
  $oXml-myCleverValue = 'something unrelated';
 
  whoops the client web service stopped processing our request successfully
 because the clever new node inadvertently broke the validation against the
 xsd.
 
  or I'm running through some code and see it in a for loop
 
  foreach($oXml as $node = $value)
 
  but I don't see any clever value in the docs from the vendor..
 
  Separation of concerns for data. The same reason you have a typical
 directory structure on an operating system and the same reason you don't
 have 10 projects all in the same vcs repository. but nothing is written in
 stone..

 Whoa, whoa, whoa! At what point did I say I think it's ok to put arbitrary
 data into $_POST?


when you suggested to OP to put the result of a query into $_POST.


 As I said in a previous email, I was responding to the OP's question which
 was essentially is it possible to fake a form post and the answer is yes


the question was more like, how do i abstract the input for a template such
that it can be supplied data via $_POST in one case and the result of a
select in another.


 I have at no point advocated using $_POST for data that you simply want to
 be globally available.


you've recommended populating $_POST with data that has nothing to do with
HTTP POST, it is by nature globally available.

-nathan


Re: [PHP] $_POST vars

2011-04-13 Thread Nathan Nobbe
On Wed, Apr 13, 2011 at 11:49 AM, Jim Giner jim.gi...@albanyhandball.comwrote:

 Can one create a set of $_POST vars within a script or is that not do-able?
 My display portion of my script utilizes the POST array to supply values to
 my input screen - this works well for the first display of an empty screen,
 and any following re-displays if there's an error in the user's input.  But
 I want to use this same script/screen to display the results of a query
 when
 the user wants to update an existing record.


While a user script can populate $_POST this is generally prohibited as it's
typically populated by the environment.

It would probly be cleaner to have the display portion of your script read
from an arbitrary array.

Said arbitrary array could be populated by $_POST in one case and the
results of a query in another case.

-nathan


Re: [PHP] $_POST vars

2011-04-13 Thread Nathan Nobbe
On Wed, Apr 13, 2011 at 12:04 PM, Stuart Dallas stu...@3ft9.com wrote:

 On Wednesday, 13 April 2011 at 18:55, Nathan Nobbe wrote:
 On Wed, Apr 13, 2011 at 11:49 AM, Jim Giner jim.gi...@albanyhandball.com
 wrote:
 
   Can one create a set of $_POST vars within a script or is that not
 do-able?
   My display portion of my script utilizes the POST array to supply
 values to
   my input screen - this works well for the first display of an empty
 screen,
   and any following re-displays if there's an error in the user's input.
 But
   I want to use this same script/screen to display the results of a query
   when
   the user wants to update an existing record.
 
 
  While a user script can populate $_POST this is generally prohibited as
 it's
  typically populated by the environment.
 
  It would probly be cleaner to have the display portion of your script
 read
  from an arbitrary array.
 
  Said arbitrary array could be populated by $_POST in one case and the
  results of a query in another case.

 While I don't necessarily disagree with you as far as abstracting the
 source of data goes, but it's never prohibited, it just considered bad
 practice.


considered a bad practice means prohibited for most groups ive worked with.

Personally I've never understood this thou shalt protect the superglobals
 attitude. They're arrays, nothing more, use them in whatever way you want
 to. They're not sacred, endangered or likely to be overcome with the urge to
 kill you if you modify them. If your code changes its behaviour depending
 upon whether the data you're dealing with has come from within or without
 your code I think you have bigger style issues to address.


the reason it's a bad practice is it undermines an assumption that $_POST is
only being populated by the environment, which in the case of $_POST is
coming from a form field, ajax / curl request etc.  as soon as that
assumption is thrown out the window debugging becomes more involved trying
to track down the mysterious appearance of a $_POST var.  if you really need
to store arbitrary data in a supergloabal $GLOABALS is there for that; def
don't stuff these into $_POST :)

keep things cleanly separated and you'll thank yourself later imo.  also
when someone is asking a question of this nature, obviously this is the most
critical time to tell them about bad practices rather than just the obvious,
yes, of course you can do that  otherwise people asking questions
won't get much more mileage from this list than a google search.

-nathan


Re: [PHP] $_POST vars

2011-04-13 Thread Nathan Nobbe
Shrug, it's called reply-all and it's been brought up here before :)

-nathan

On Wed, Apr 13, 2011 at 12:25 PM, Jim Giner jim.gi...@albanyhandball.comwrote:

 No need to email me AND send to the list.  Is that the standard practice on
 this forum?  Not encountered it before.




Re: [PHP] $_POST vars

2011-04-13 Thread Nathan Nobbe
On Wed, Apr 13, 2011 at 12:34 PM, Stuart Dallas stu...@3ft9.com wrote:

 On Wednesday, 13 April 2011 at 19:15, Nathan Nobbe wrote:
 On Wed, Apr 13, 2011 at 12:04 PM, Stuart Dallas stu...@3ft9.com wrote:
   On Wednesday, 13 April 2011 at 18:55, Nathan Nobbe wrote:
On Wed, Apr 13, 2011 at 11:49 AM, Jim Giner 
 jim.gi...@albanyhandball.comwrote:
   
 Can one create a set of $_POST vars within a script or is that not
 do-able?
 My display portion of my script utilizes the POST array to supply
 values to
 my input screen - this works well for the first display of an empty
 screen,
 and any following re-displays if there's an error in the user's
 input. But
 I want to use this same script/screen to display the results of a
 query
 when
 the user wants to update an existing record.
   
   
While a user script can populate $_POST this is generally prohibited
 as it's
typically populated by the environment.
   
It would probly be cleaner to have the display portion of your script
 read
from an arbitrary array.
   
Said arbitrary array could be populated by $_POST in one case and the
results of a query in another case.
  
   While I don't necessarily disagree with you as far as abstracting the
 source of data goes, but it's never prohibited, it just considered bad
 practice.
 
  considered a bad practice means prohibited for most groups ive worked
 with.

 This isn't any of the groups you've worked with, this is the wide world and
 it's full of possibilities.


lol youre right, and none of the groups ive worked with have been part of
this global community, so these must be strictly new possibilities we're
discussing on this thread...


  Personally I've never understood this thou shalt protect the
 superglobals attitude. They're arrays, nothing more, use them in whatever
 way you want to. They're not sacred, endangered or likely to be overcome
 with the urge to kill you if you modify them. If your code changes its
 behaviour depending upon whether the data you're dealing with has come from
 within or without your code I think you have bigger style issues to address.
 the reason it's a bad practice is it undermines an assumption that $_POST
 is only being populated by the environment, which in the case of $_POST is
 coming from a form field, ajax / curl request etc. as soon as that
 assumption is thrown out the window debugging becomes more involved trying
 to track down the mysterious appearance of a $_POST var. if you really need
 to store arbitrary data in a supergloabal $GLOABALS is there for that; def
 don't stuff these into $_POST :)

 My idea of best practice says that data coming in from outside your code
 should only ever be dealt with in the first script the request hits, so you
 should never be hunting for where an errant value in $_POST came from. Given
 this (and noting the fact that this was your suggestion to the OP) you're
 creating the problem you're trying to avoid by using an arbitrary array in
 the place of $_POST.


well when you build programs that are more than one script in length you'll
find that data submitted by the user is often referenced further in the flow
than the entry script.. read: front controller.  and im not creating a
problem, im avoiding a problem by not overloading the intended use of the
$_POST array.


 My response to the OP was simply answering the question.


right, don't bother to offer any insight to a beginner, undermining the
benefit of a list like php-general.


 He has a section of code that uses $_POST and he wants to know if he can
 populate that within his code rather than needing it to come from a request.
 Why he didn't just try it is beyond me, but all this talk of best and bad
 practice is all beside the point.


no, it's the entire point.  if you ask a question on this list you should
expect to get more than a black and white answer.  that's how people get
better quicker and that's the point of interacting with humans on the other
end of the wire.


  keep things cleanly separated and you'll thank yourself later imo. also
 when someone is asking a question of this nature, obviously this is the most
 critical time to tell them about bad practices rather than just the obvious,
 yes, of course you can do that otherwise people asking questions won't
 get much more mileage from this list than a google search.

 It's bad practice for reasons that arise equally well from abstracting the
 source of data, as you suggested. Why, then, is it bad practice?


no, it's actually a better practice.  users are expected to populate arrays
they create.  the $GLOBALS array is expected to be populated by user
scripts.  The $_POST array is expected to be populated by PHP.  by the time
you've decided to stuff variables into $_GET or $_POST yourself you've
decided to start mixing variables from your code with variables from the
client.  simply put these arrays are not intended to be populated by user
scripts.

-nathan


[PHP] xinetd vs php socket server

2011-03-28 Thread Nathan Nobbe
Hi,

I'd like to bat around some pros / cons of selecting xinetd to implement a
socket server.  From my perspective the list is something like this:

xinetd pros
 . no need to rewrite forking functionality, 'server' can be written as
simple php script
 . forking potentially faster than php-based implementation

xinetd cons
 . time tradeoff learning xinetd configuration vs coding in support directly
in php implementation
 . potentially less maintainable depending on staff, likely php dev team
more capable of maintaining 100% php solution

Interested in your thoughts!

-nathan


Re: [PHP] xinetd vs php socket server

2011-03-28 Thread Nathan Nobbe
On Mon, Mar 28, 2011 at 12:38 PM, Bostjan Skufca bost...@a2o.si wrote:

 Xinetd will definitely be faster way than coding your daemon in PHP.


In this case:

 You have to consider many other things as well:
 - do your worker processes run under various UIDs (do they do
 setuid/setgid)?

no


 - do your workers die after processing each request/client or do they
 process multiple connections?

die after each request


 - do you need inter-worker communication?

no


 - resource locking issues, etc?

perhaps some, but i think this could be handled via a select to the database
prior to a write


 What is your goal, the function of your daemon/socket server?

basically to process an incoming payload from a client, parse and store the
results.  not sure why the requirements are to accept the payload over
non-http, but that is out of my control.

i guess you can see where im going with this, basically, why reinvent the
wheel w/ the daemon code when xinetd is available.  i suppose those php
libraries you mentioned are an argument against that, but then there is the
speed benefit of xinetd.  i guess it just comes down to a battle of
tradeoffs.

-nathan


Re: [PHP] xinetd vs php socket server

2011-03-28 Thread Nathan Nobbe
On Mon, Mar 28, 2011 at 3:34 PM, Bostjan Skufca bost...@a2o.si wrote:

 If you need high performance you probably already know that it will be very
 expensive CPU wise if workers are spawned on each request. If you don't, I
 would not bother with daemon and just use xinetd. You can always add
 daemon-handling stuff later on.

 Well I do hope you find a good working solution with as little
 inconvenience as possible,
 b.


hmm, wouldn't both the solutions most likely be forking?  php daemon would
fork since threading isn't supported, and xinetd, probly best to have it
fork for the same reason apache is typically configured to fork.  right?

-nathan


Re: [PHP] PHP session replication

2011-03-18 Thread Nathan Nobbe
On Fri, Mar 18, 2011 at 11:19 AM, Stuart Dallas stu...@3ft9.com wrote:

 On Friday, 18 March 2011 at 17:14, Torsten Rosenberger wrote:

  I'm curious to know what people are storing in their sessions. Is there
 anything larger than a few hundred bytes that is specific and unique to that
 session storage? What are the use cases for server-side session storage
 because it seems like I'm missing something?
 
  I store user rights in the session but also possible to do it with a DB
 query every time.

 Why not store those in an encrypted cookie? Unless we're talking about more
 than a couple of hundred bytes I see no reason to store them separately
 server-side or to hit the DB each time.


Stuart, would you not agree that sending any amount of data over the wire
takes more time than passing it over an internal network?  From my
perspective the tradeoffs of cookies vs. server side session storage are
application performance and cost of ownership.

An application will be more responsive if less data is sent over the wire on
each request however running a distributed session store on the server side
can be expensive monetarily.  Storing session data in cookies has it's
merits, but I think they start to loose their benefits on large sites.  The
way I see it they can be a great way to cope with startup costs and
server-side complexity on low traffic sites.

-nathan


Re: [PHP] PHP session replication

2011-03-18 Thread Nathan Nobbe
On Fri, Mar 18, 2011 at 11:56 AM, Stuart Dallas stu...@3ft9.com wrote:

 On Friday, 18 March 2011 at 17:36, Nathan Nobbe wrote:
 On Fri, Mar 18, 2011 at 11:19 AM, Stuart Dallas stu...@3ft9.com wrote:
   On Friday, 18 March 2011 at 17:14, Torsten Rosenberger wrote:
 I'm curious to know what people are storing in their sessions. Is
 there anything larger than a few hundred bytes that is specific and unique
 to that session storage? What are the use cases for server-side session
 storage because it seems like I'm missing something?
   
I store user rights in the session but also possible to do it with a
 DB query every time.
  
   Why not store those in an encrypted cookie? Unless we're talking about
 more than a couple of hundred bytes I see no reason to store them separately
 server-side or to hit the DB each time.
 
  Stuart, would you not agree that sending any amount of data over the wire
 takes more time than passing it over an internal network? From my
 perspective the tradeoffs of cookies vs. server side session storage are
 application performance and cost of ownership.
 
  An application will be more responsive if less data is sent over the wire
 on each request however running a distributed session store on the server
 side can be expensive monetarily. Storing session data in cookies has it's
 merits, but I think they start to loose their benefits on large sites. The
 way I see it they can be a great way to cope with startup costs and
 server-side complexity on low traffic sites.

 Agreed, but how much traffic do you need to be getting for an extra 127
 bytes per request to make a noticeable addition to page response times or
 your bandwidth bill?

 I just logged in to the main site on which I use this mechanism and checked
 the headers sent by the browser. This is what got sent...

 Cookie: t=HgiivpyFIVX62BYIe4PSg4de04I92qTa1aL6yu8vQDI%3D; expires=Sat,
 17-Mar-2012 17:39:36 GMT; path=/; domain=example.co.uk

 That's 126 bytes plus the LF, and that's assuming that your site sets no
 other cookies. If it does then the extra weight is only 118 bytes. Obviously
 this varies slightly but essentially we're talking about a very small
 overhead per request. My strategy specifically aims to limit the amount of
 data stored in cookies - I don't use sessions to store anything that's not
 absolutely necessary.

 I would argue that an application will get more responsive with every
 server-side shared resource you remove from the equation. Compare the time
 taken to receive an extra 118 bytes and decrypt that data to the time taken
 to make a request to a shared data storage system, bearing in mind that such
 a system will get slower as the number of concurrent requests increases.

 I agree that for sites with huge amounts of traffic need to look at this
 type of problem differently, but I think the level at which your perspective
 changes is very high. The main site on which I use this cookie-based system
 peaks at ~400 reqs/sec and pushes out just under 1.5TB of HTML per month.
 I've done the calculations and the cost of maintaining a server-side session
 store are huge compared to the extra bandwidth used by the cookies.


Yes, I think it makes sense to start out storing sessions in cookies and
consider a server-side move only when it makes sense.


 If your app really needs to store large amounts of data in sessions (and
 I'm yet to have anyone give me a solid example) then the maths will flip and
 server-side storage becomes the cheaper option.


I worked at a site that is roughly the 25th largest on the net in terms of
traffic.  This is where I was originally exposed to the tradeoffs of session
storage in cookies vs server-side.  Until then I presumed things were almost
always done server-side.  However, if you look at Code Igniter and I'd
hazard a guess at a number of other frameworks, the default session store is
cookies!  This was perplexing until I started to work at the site mentioned
above (remains nameless tho:)), where I was actually able to discuss pros 
cons thereof.

CI seemed to have a problem in that it would not spill data over into
additional cookies when the size of one cookie was maxed out.  One way to
tell it's time to rethink your paradigm is when you're using up the maximum
number of cookies for a given domain to propagate data between requests -
been there, lol.

I'm surprised this concept was such as surprise to many of the list members,
I thought this was a well know paradigm, storing session data in cookies.

-nathan


Re: [PHP] PHP session replication

2011-03-18 Thread Nathan Nobbe
On Fri, Mar 18, 2011 at 11:58 AM, Richard Quadling rquadl...@gmail.comwrote:

 On 18 March 2011 17:36, Nathan Nobbe quickshif...@gmail.com wrote:
  On Fri, Mar 18, 2011 at 11:19 AM, Stuart Dallas stu...@3ft9.com wrote:
 
  On Friday, 18 March 2011 at 17:14, Torsten Rosenberger wrote:
 
   I'm curious to know what people are storing in their sessions. Is
 there
  anything larger than a few hundred bytes that is specific and unique to
 that
  session storage? What are the use cases for server-side session storage
  because it seems like I'm missing something?
  
   I store user rights in the session but also possible to do it with a
 DB
  query every time.
 
  Why not store those in an encrypted cookie? Unless we're talking about
 more
  than a couple of hundred bytes I see no reason to store them separately
  server-side or to hit the DB each time.
 
 
  Stuart, would you not agree that sending any amount of data over the wire
  takes more time than passing it over an internal network?  From my
  perspective the tradeoffs of cookies vs. server side session storage are
  application performance and cost of ownership.
 
  An application will be more responsive if less data is sent over the wire
 on
  each request however running a distributed session store on the server
 side
  can be expensive monetarily.  Storing session data in cookies has it's
  merits, but I think they start to loose their benefits on large sites.
  The
  way I see it they can be a great way to cope with startup costs and
  server-side complexity on low traffic sites.
 
  -nathan
 

 The addition of a small cookie would far outweigh all the
 communication to and from the SQL server (even though it is only
 memory).

 Consider that you are going to be getting a session cookie from the
 client, substituting the cookie for compressed/encrypted data should
 be very quick. Nothing more than a bit of string manip.


Well that and travelling over the Internet, which is where the slow down
comes in.


 The actually traffic for a channel to a SQL db is going to be a little
 more than a few bytes. All the handshaking and SQL server processing
 of the SQL statement, the data retrieval and packaging and
 transmission ...


I dunno, I'd say that should still be faster given that it's all on one side
of a wide area network, but for really small pieces of data it could be
slower.

I'd say that for the right circumstances, putting the session data in
 the cookie would be beneficial.


No doubt - especially when you're starting a company and looking at a bare
pocket book!

-nathan


Re: [PHP] PHP session replication

2011-03-17 Thread Nathan Nobbe
On Wed, Mar 16, 2011 at 10:06 PM, Alessandro Ferrucci 
alessandroferru...@gmail.com wrote:

 Hello,
 I'm curious, what are the most popular methods to perform session
 replication across http servers in PHP?
 I've read about repcache(memcached module) and Mysql.
 anything else?  is there some mod_php_session_replication httpd module?
 thanks


I recently posted a question to the memcached mailing list about this.  I
would suggest looking at membase if you're interested in that route.

Pragmatically speaking though, I'd say go for database backed sessions until
they actually become a performance bottleneck.

Here's the post from google groups if you're interested:

http://groups.google.com/group/memcached/browse_thread/thread/7ed750db888e6b1b?pli=1

-nathan


Re: [PHP] PHP session replication

2011-03-17 Thread Nathan Nobbe
On Thu, Mar 17, 2011 at 9:03 AM, Joel j...@wearegrand.com wrote:

 Take a look at MCache: http://www.mohawksoft.org/?q=node/8

 A drop in distributed replacement for php sessions.


One important distinction to draw is that distributed != replicated.
 Replication is something extra, as the discussion I linked to illustrates.

Looking over the homepage for MCache regarding replication:

Is mcache redundant? No.

Though it does appear MCache supports a persistent store (NFS or SQL
backend).

What OP initially suggested, repcache, does add replication for memcached,
however it does not add a persistent store; membase offers replication +
persistent store so it seems well suited for session storage.

-nathan


Re: [PHP] Somewhat OT - Stored Procedures

2011-03-09 Thread Nathan Nobbe
On Wed, Mar 9, 2011 at 3:18 AM, Richard Quadling rquadl...@gmail.comwrote:

 On 7 March 2011 23:37, Nathan Nobbe quickshif...@gmail.com wrote:
  On Fri, Mar 4, 2011 at 7:29 AM, Richard Quadling rquadl...@gmail.com
  wrote:
 
  On 3 March 2011 18:30, Nathan Nobbe quickshif...@gmail.com wrote:
   Hey gang,
  
   (Yes Tedd, I like your style, when it pertains to how you address the
   list
   :))
  
   I have a new curiosity that's arisen as a result of a new contract I'm
   working on, I'd like to bounce around some thoughts off the list and
 see
   what you folks think if interested.
  
   The topic at hand is stored procedures.  Frankly, I've hardly ever
 even
   seen
   these in use, and what I'm trying to figure out are good rules of
 thumb
   as
   to where / when / how they are best used in application development.
  
   Also, bear in mind that personally I tend to favor OO paradigms for
   application development so would prefer feedback that incorporates
 that
   tendency.
  
   Initial thoughts are
  
   Bad:
   . Not well suited for ORM, particularly procedures which return
 multiple
   result sets consisting of columns from multiple tables
   . Greater potential for duplicated logic, I think this comes down to a
   well
   defined set of rules for any given application, read: convention
   required
   for success
   . Scripting languages are vendor specific, and likely most application
   developers have a limited understanding thereof
  
   Good:
   . Better performance
   . Fill in blank on convincing bullets here
  
   I've also done some reading on MSSQL vs. MySQL and found that the
 former
   offers much more features.  I've also read that most databases only
 see
   roughly 40% of the feature sets being used for typical applications in
   the
   wild, and would agree from personal experience it is accurate.
  
   From my standpoint MySQL is popular because the features it offers are
   the
   features folks are really looking, one of those 80/20 things...
  
   I stumbled into this link on a google search, it's from '04 but looks
 to
   be
   relevant to this day
  
  
  
 http://www.codinghorror.com/blog/2004/10/who-needs-stored-procedures-anyways.html
  
   Your thoughts appreciated,
  
   -nathan
  
 
  Hello Nathan.
 
  I develop for and on Windows using IIS7 and MS SQL Server
  7/2000/2005/2008.
 
  i love how you preface many of your responses like this.
 
 
  Almost exclusively I use prepared statements to talk to stored
  procedures and views. I use triggers and constraints to enforce RDI. I
  _do_ have the occasional hacky script which includes SQL, but only
  'cause I was being lazy and wanted to do a one off change.
 
  this sounds as if you're doing next to 0 query generation from php, is
 that
  correct?
 
  At a fundamental level, my PHP code isn't concerning itself with any
  physical data structures. As much as possible my PHP code treats the
  sql data source as a processor ready to supply data in a standardized
  form (even hierarchical) and to accept data for storage (again
  hierarchical). My PHP code knows next to nothing about the table
  structure (why should it - it isn't a database). It does know that a
  customer object has a set of properties and a set of instruments of
  change which are passed to the SQL server to effect the data and are
  cached locally. PHP deals in objects/entities. Stored procedures
  provide the translation between the OOP and the RDBMS. This provides a
  nice clean interface between PHP and the data. The stored procedures
  and views are all pre-compiled - with their internal usage statistics
  to make best use of available indices and are tuned to the actual data
  rather than something I thought I knew about the data usage when I
  designed the DB. So speed is much more significant. Having every
  single SQL statement compiled from scratch for a 1 off use would seem
  wasteful.
 
  Multiple result sets are completely fine (at least for MS SQL Server)
  - Admittedly you have to currently process the result sets in
  sequential order (i.e. set 1 before moving to set 2 - can't move back
  to set 1). But that is something quite easy to work with when you know
  the limitation. And is the easiest way to get hierarchical data into
  PHP for me. I get all the relevant data in 1 hit rather than getting
  the data with potential mis-matching values due to the realtime
  multi-user environment.
 
  i understand the ability to consume multiple result sets is available.
  the
  issue i think would be raised with an orm would be getting result sets
 with
  mixed columns from multiple tables.  im not sure how capable an orm like
  propel (for example) is of mapping those results back to objects.  at a
  glance of google results it appears the result is just an array which
  sacrifices the abstraction the orm aims to provide.
  -nathan

 All my new projects are using stored procedures and views. No direct
 access to the tables. This means that if I use

Re: [PHP] Somewhat OT - Stored Procedures

2011-03-07 Thread Nathan Nobbe
On Fri, Mar 4, 2011 at 7:29 AM, Richard Quadling rquadl...@gmail.comwrote:

 On 3 March 2011 18:30, Nathan Nobbe quickshif...@gmail.com wrote:
  Hey gang,
 
  (Yes Tedd, I like your style, when it pertains to how you address the
 list
  :))
 
  I have a new curiosity that's arisen as a result of a new contract I'm
  working on, I'd like to bounce around some thoughts off the list and see
  what you folks think if interested.
 
  The topic at hand is stored procedures.  Frankly, I've hardly ever even
 seen
  these in use, and what I'm trying to figure out are good rules of thumb
 as
  to where / when / how they are best used in application development.
 
  Also, bear in mind that personally I tend to favor OO paradigms for
  application development so would prefer feedback that incorporates that
  tendency.
 
  Initial thoughts are
 
  Bad:
  . Not well suited for ORM, particularly procedures which return multiple
  result sets consisting of columns from multiple tables
  . Greater potential for duplicated logic, I think this comes down to a
 well
  defined set of rules for any given application, read: convention required
  for success
  . Scripting languages are vendor specific, and likely most application
  developers have a limited understanding thereof
 
  Good:
  . Better performance
  . Fill in blank on convincing bullets here
 
  I've also done some reading on MSSQL vs. MySQL and found that the former
  offers much more features.  I've also read that most databases only see
  roughly 40% of the feature sets being used for typical applications in
 the
  wild, and would agree from personal experience it is accurate.
 
  From my standpoint MySQL is popular because the features it offers are
 the
  features folks are really looking, one of those 80/20 things...
 
  I stumbled into this link on a google search, it's from '04 but looks to
 be
  relevant to this day
 
 
 http://www.codinghorror.com/blog/2004/10/who-needs-stored-procedures-anyways.html
 
  Your thoughts appreciated,
 
  -nathan
 

 Hello Nathan.

 I develop for and on Windows using IIS7 and MS SQL Server 7/2000/2005/2008.


i love how you preface many of your responses like this.


 Almost exclusively I use prepared statements to talk to stored
 procedures and views. I use triggers and constraints to enforce RDI. I
 _do_ have the occasional hacky script which includes SQL, but only
 'cause I was being lazy and wanted to do a one off change.


this sounds as if you're doing next to 0 query generation from php, is that
correct?

At a fundamental level, my PHP code isn't concerning itself with any
 physical data structures. As much as possible my PHP code treats the
 sql data source as a processor ready to supply data in a standardized
 form (even hierarchical) and to accept data for storage (again
 hierarchical). My PHP code knows next to nothing about the table
 structure (why should it - it isn't a database). It does know that a
 customer object has a set of properties and a set of instruments of
 change which are passed to the SQL server to effect the data and are
 cached locally. PHP deals in objects/entities. Stored procedures
 provide the translation between the OOP and the RDBMS. This provides a
 nice clean interface between PHP and the data. The stored procedures
 and views are all pre-compiled - with their internal usage statistics
 to make best use of available indices and are tuned to the actual data
 rather than something I thought I knew about the data usage when I
 designed the DB. So speed is much more significant. Having every
 single SQL statement compiled from scratch for a 1 off use would seem
 wasteful.

 Multiple result sets are completely fine (at least for MS SQL Server)
 - Admittedly you have to currently process the result sets in
 sequential order (i.e. set 1 before moving to set 2 - can't move back
 to set 1). But that is something quite easy to work with when you know
 the limitation. And is the easiest way to get hierarchical data into
 PHP for me. I get all the relevant data in 1 hit rather than getting
 the data with potential mis-matching values due to the realtime
 multi-user environment.


i understand the ability to consume multiple result sets is available.  the
issue i think would be raised with an orm would be getting result sets with
mixed columns from multiple tables.  im not sure how capable an orm like
propel (for example) is of mapping those results back to objects.  at a
glance of google results it appears the result is just an array which
sacrifices the abstraction the orm aims to provide.

-nathan


Re: [PHP] Re: Somewhat OT - Stored Procedures

2011-03-07 Thread Nathan Nobbe
On Sat, Mar 5, 2011 at 5:31 AM, Florin Jurcovici florin.jurcov...@gmail.com
 wrote:

 Hi.

 I would always recommend stored procedures, as long as there are a
 very few rules obeyed:
 - keep them simple - they should mostly implement just CRUD operations
 plus application-specific searches, and should not encapsulate any
 other logic


i dont see the value in this approach, read more below.


 - use just portable SQL (well, as long as this is possible)

 My reasoning for using stored procedures and sticking to these rules
 is the following:
 - no matter what you do, especially with PHP, you can't achieve the
 same performance if you generate your SQL on the fly as when you just
 call a precompiled stored procedure


is this performance advantage enough to merit pushing all the queries to
stored procedures?  id love to see some benchmarks.


 - by keeping stored procedures very simple, and sticking to the
 convention of packing just CRUD + specialized searches into them, plus
 using just portable SQL, inasmuch as possible, you can easily switch
 databases - in most cases, just copying over the stored procedures
 does the trick


i doubt it takes the database long to compile trivial crud queries.  i doubt
these would see much performance gain implemented as stored procedures
rather than generated by a php script.


 - for the same reasons listed for the previous point, the readability
 of your application is much improved - reading
 users_getByLogin(:login) is IMO easier to comprehend than SELECT *
 FROM USERS WHERE loginName = :login, without sacrificing any
 performance or portability, compared to using inline SQL statements as
 strings


this doesn't make much sense, since in php i can easily write a function
users_getByLogin($login) which provides the same readability advantage.
 after all this would be invoked via the function name throughout the
source.


 The consequences of not sticking to the above listed two criteria can
 be very bad:
 - packing more than reasonable logic into the database makes your
 application incomprehensible - for instance
 company_doMonthEndCalculations() is likely to include such a huge
 quantity of logic, that the PHP code calling it is mostly irrelevant,
 and you must actually comprehend both the details of the SQL in the
 database (in the stored procedures) and the way PHP is connecting them
 to understand an application - obviously harder if you have all your
 logic in just one place


this makes a lot of sense and gets into the issue of how much application
logic if any would be encapsulated in a stored procedure layer.
 doMonthEndCalculations does sound really scary lol!


 - whereas if packing only very specific and simple operations into
 stored procedures allows you to keep the design of the PHP application
 very object-oriented, packing very much logic into stored procedures
 may cause your PHP code to be just an adapter to an application
 written in SQL, instead of being the application itself; SQL being
 procedural, your application will have all the flexibility,
 extensibility and maintainability problems that a non-OO design causes


this is a definite issue.  when deciding to implement large chunks of domain
logic in stored procedures, it must be considered that the expressiveness of
these db scripting languages are not as extensive as the languages used to
implement the application layer.

from a performance perspective i think pre-compiling large complex queries
may be advantageous, but i suspect for trivial queries the difference may be
marginal.  some benchmarks would be helpful in this area if anyone knows
where to find them.

-nathan


[PHP] Re: Regex for extracting quoted strings

2011-03-05 Thread Nathan Rixham

Mark Kelly wrote:

Hi.

I'm hoping someone can help me extract text between double quotes from a 
string.


$regex = 'some magic';
$r = preg_match($regex, $sentence, $phrases);

So, if 

$sentence = 'Dave said This is it. Nope, that is the wrong colour she 
replied.';


I want $phrases to contain 'This is it' and 'Nope, that is the wrong colour'.

Can anyone help?


$regex = '/(.*)/imU';
$r = preg_match_all($regex, $sentence, $phrases);


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



[PHP] Re: Delaying $(document).ready() in jQuery until php script finish

2011-03-04 Thread Nathan Rixham

Richard Sharp wrote:

I have been banging my head trying to figure out how to delay
$(document).ready() command until my php script finish running and load
data into a csv file.  Any ideas


*which* PHP script? are you returning an HTML document then keeping the 
script going in the background, /or/ are you requesting another script 
(by js, clicking a link, posting a form), /or/?


I know it's a jQuery question, but it might be a PHP related gotcha.

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



[PHP] Re: Somewhat OT - Stored Procedures

2011-03-04 Thread Nathan Rixham

Hi Nathan,

Nathan Nobbe wrote:

Also, bear in mind that personally I tend to favor OO paradigms for
application development so would prefer feedback that incorporates that
tendency.

Initial thoughts are

Bad:
. Not well suited for ORM, particularly procedures which return multiple
result sets consisting of columns from multiple tables
. Greater potential for duplicated logic, I think this comes down to a well
defined set of rules for any given application, read: convention required
for success
. Scripting languages are vendor specific, and likely most application
developers have a limited understanding thereof

Good:
. Better performance
. Fill in blank on convincing bullets here


It's a trade-off thing, and to be looked at on a case by case basis. The 
major factors are


 - closer to the iron (better performance, as you said)
 - information hiding and security
 - code portability

If you have multiple clients all doing the same procedure/routine then 
it can be wise to used stored procedures/routines, even just for things 
like administration and optimization, because the routine is decoupled 
from the app tier, with just the interface exposed, you can optimize 
without having to change app tier code, delegate to db admins and suchlike.


Likewise, information hiding is also a property of security, you can 
expose the bare minimum without letting developers, or those with access 
to the code, see the full database layout and structure. Similarly you 
can set up logging at procedure level, and ensure acidity of 
transactions at db level.


Some of the key factors though, are design choices in the way you code 
applications, OO and using ORMs is a significant choice, and perhaps 
you're better staying with what's familiar and delegating / trusting the 
ORM layer + visible code which you're used to and can tweak easily.


If you were developing C/++ and running on pl-sql over virtuoso or 
something the advice may be different.


Do remember that you aren't tied to RDBMS in any way though, there's a 
huge world of [ http://nosql-database.org/ choices and styles ] out 
there that also should/could be considered, many of which suit the OO 
style far better ;)


Best,

Nathan (namesake)

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



Re: [PHP] Somewhat OT - Stored Procedures

2011-03-04 Thread Nathan Rixham

Richard Quadling wrote:

At a fundamental level, my PHP code isn't concerning itself with any
physical data structures. As much as possible my PHP code treats the
sql data source as a processor ready to supply data in a standardized
form (even hierarchical) and to accept data for storage (again
hierarchical). My PHP code knows next to nothing about the table
structure (why should it - it isn't a database). 


Exactly - separation of concerns, a core principal to learn and apply 
wherever you can.


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



Re: [PHP] something about dates in mysql

2011-03-03 Thread Nathan Rixham

Richard Quadling wrote:

On 3 March 2011 10:09, Webforlaget.dk i...@web-forlaget.dk wrote:

I need help to know Why this dont work ?

-

 $thisdate =date(Y-m-d,mktime(0,0,0,$mth, $day, $year));

 $sql  = SELECT id,case,startdate,enddate FROM table WHERE startdate=$thisdate AND 
enddate=$thisdate ORDER BY startdate;

-

The result should be an array whith open cases at $thisdate, but nothing appear.

Is it something about dates in mysql ?

Thanks for any advice.

Best regards,

Venlige hilsner

Rolf Brejner


I think that dates in SQL statements need to be in the quotes as they
are strings and not integers.

So, try ...

$sql  = SELECT id,case,startdate,enddate FROM table WHERE
startdate='$thisdate' AND enddate='$thisdate' ORDER BY startdate;

I'm surprised you don't get an error

Ah. As it stands, the SQL is something like ...

WHERE startdate = 2010 - 3 - 3

So, probably the actual test that is being executed is 

WHERE startdate = 2004

Which, for a date stamp will never return anything sensible.


yes, and remember the DATE and FROM_UNIXTIME mysql functions too.

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



[PHP] Somewhat OT - Stored Procedures

2011-03-03 Thread Nathan Nobbe
Hey gang,

(Yes Tedd, I like your style, when it pertains to how you address the list
:))

I have a new curiosity that's arisen as a result of a new contract I'm
working on, I'd like to bounce around some thoughts off the list and see
what you folks think if interested.

The topic at hand is stored procedures.  Frankly, I've hardly ever even seen
these in use, and what I'm trying to figure out are good rules of thumb as
to where / when / how they are best used in application development.

Also, bear in mind that personally I tend to favor OO paradigms for
application development so would prefer feedback that incorporates that
tendency.

Initial thoughts are

Bad:
. Not well suited for ORM, particularly procedures which return multiple
result sets consisting of columns from multiple tables
. Greater potential for duplicated logic, I think this comes down to a well
defined set of rules for any given application, read: convention required
for success
. Scripting languages are vendor specific, and likely most application
developers have a limited understanding thereof

Good:
. Better performance
. Fill in blank on convincing bullets here

I've also done some reading on MSSQL vs. MySQL and found that the former
offers much more features.  I've also read that most databases only see
roughly 40% of the feature sets being used for typical applications in the
wild, and would agree from personal experience it is accurate.

From my standpoint MySQL is popular because the features it offers are the
features folks are really looking, one of those 80/20 things...

I stumbled into this link on a google search, it's from '04 but looks to be
relevant to this day

http://www.codinghorror.com/blog/2004/10/who-needs-stored-procedures-anyways.html

Your thoughts appreciated,

-nathan


Re: [PHP] Somewhat OT - Stored Procedures

2011-03-03 Thread Nathan Nobbe
On Thu, Mar 3, 2011 at 12:23 PM, Steve Staples sstap...@mnsi.net wrote:

 On Thu, 2011-03-03 at 11:30 -0700, Nathan Nobbe wrote:
  Hey gang,
 
  (Yes Tedd, I like your style, when it pertains to how you address the
 list
  :))
 
  I have a new curiosity that's arisen as a result of a new contract I'm
  working on, I'd like to bounce around some thoughts off the list and see
  what you folks think if interested.
 
  The topic at hand is stored procedures.  Frankly, I've hardly ever even
 seen
  these in use, and what I'm trying to figure out are good rules of thumb
 as
  to where / when / how they are best used in application development.
 
  Also, bear in mind that personally I tend to favor OO paradigms for
  application development so would prefer feedback that incorporates that
  tendency.
 
  Initial thoughts are
 
  Bad:
  . Not well suited for ORM, particularly procedures which return multiple
  result sets consisting of columns from multiple tables
  . Greater potential for duplicated logic, I think this comes down to a
 well
  defined set of rules for any given application, read: convention required
  for success
  . Scripting languages are vendor specific, and likely most application
  developers have a limited understanding thereof
 
  Good:
  . Better performance
  . Fill in blank on convincing bullets here
 
  I've also done some reading on MSSQL vs. MySQL and found that the former
  offers much more features.  I've also read that most databases only see
  roughly 40% of the feature sets being used for typical applications in
 the
  wild, and would agree from personal experience it is accurate.
 
  From my standpoint MySQL is popular because the features it offers are
 the
  features folks are really looking, one of those 80/20 things...
 
  I stumbled into this link on a google search, it's from '04 but looks to
 be
  relevant to this day
 
 
 http://www.codinghorror.com/blog/2004/10/who-needs-stored-procedures-anyways.html
 
  Your thoughts appreciated,
 
  -nathan


Hi Steve,

Thanks for the response.


 Would this not be a better suited question for the mysql mailing list?


Well they may be able to share some more database-centric advantages with
me, however, I'm interested in the merit of stored procedures from an
application perspective.  Something that Paul touched on for example would
be who is writing these procedures.  In my experience having DBA's get their
hands into application design is bad.  Also, if 1 out of 10 devs is decent
at writing stored procedures, doesn't that jeopardize the stability /
effectiveness of the team?


 regardless, I use stored procedures and functions on my mysql server
 here at work, in regards to our radius accounting packets.

 I will say, that it was WAY easier to send the packet dump to mysql in a
 call() statement, than it was to try and do all the programming
 necessary to insert the packet, calculate user usage, is the packet
 there already, etc etc etc on the radius server.  Doing it this way, we
 have 4 radius servers that just fire the same thing over to the mysql,
 and if there is a change, i do it on the mysql server, and not have to
 do the same thing on 4 different servers.


That makes a lot of sense in the context of Radius / MySQL communication.
 Why add another layer there, and it is food for thought in future
endeavors.  I'm more interested in how they might fit into a LAMP stack
running some hosted application though.


 views, stored procedures, triggers and functions really do have their
 purpose within mysql/mssql (and whichever sql server you are using if
 they support them), and most of the times they are forgotten about
 and/or overlooked.


I have seen how these tools, in particular triggers and views fit into the
equation in an application design.  Again, I think this is something which
can be marginalized if there is not a solid convention in place describing
what is to be implemented in the database layer as opposed to the
application layer.

take a look at this article:
 http://www.tonymarston.net/php-mysql/stored-procedures-are-evil.html


Will do.


 Good luck, and I think you may get more response from
 my...@lists.mysql.com


Considering this as well, thanks for the response!

-nathan


Re: [PHP] Somewhat OT - Stored Procedures

2011-03-03 Thread Nathan Nobbe
On Thu, Mar 3, 2011 at 12:59 PM, Paul M Foster pa...@quillandmouse.comwrote:

 On Thu, Mar 03, 2011 at 11:30:49AM -0700, Nathan Nobbe wrote:

  Hey gang,
 
  (Yes Tedd, I like your style, when it pertains to how you address the
 list
  :))
 
  I have a new curiosity that's arisen as a result of a new contract I'm
  working on, I'd like to bounce around some thoughts off the list and see
  what you folks think if interested.
 
  The topic at hand is stored procedures.  Frankly, I've hardly ever even
 seen
  these in use, and what I'm trying to figure out are good rules of thumb
 as
  to where / when / how they are best used in application development.
 
  Also, bear in mind that personally I tend to favor OO paradigms for
  application development so would prefer feedback that incorporates that
  tendency.
 
  Initial thoughts are
 
  Bad:
  . Not well suited for ORM, particularly procedures which return multiple
  result sets consisting of columns from multiple tables
  . Greater potential for duplicated logic, I think this comes down to a
 well
  defined set of rules for any given application, read: convention required
  for success
  . Scripting languages are vendor specific, and likely most application
  developers have a limited understanding thereof
 
  Good:
  . Better performance
  . Fill in blank on convincing bullets here
 
  I've also done some reading on MSSQL vs. MySQL and found that the former
  offers much more features.  I've also read that most databases only see
  roughly 40% of the feature sets being used for typical applications in
 the
  wild, and would agree from personal experience it is accurate.
 
  From my standpoint MySQL is popular because the features it offers are
 the
  features folks are really looking, one of those 80/20 things...
 
  I stumbled into this link on a google search, it's from '04 but looks to
 be
  relevant to this day
 
 
 http://www.codinghorror.com/blog/2004/10/who-needs-stored-procedures-anyways.html
 
  Your thoughts appreciated,

 I've done a lot of work with databases, and never used stored
 procedures. I'm not quite sure why anyone would graft a bunch of
 computational gear on top of a database engine designed to store and
 retrieve data. Let the engine do what it does best. Leave PHP or C to
 Python to do the other stuff.


Paul, I tend to agree with you here.  The one exception that makes sense to
me is super huge data sets.  I used to ride the bus w/ a guy who was
scripting Oracle for a big insurance company.


 Another point: I once had a boss tell me that programmers were typically
 weak on database. I suspect they would gain some expertise if they were
 forced to consider database architecture and SQL in writing apps. Stored
 procedures would tend to make the database more opaque.


I think there is merit to this.  But by the time you've got some triggers
and views going I'm not so sure the procedures are worth it.  It seems to me
like things are starting to get heavy on the db side of the fence at that
point, but of course that opinion is arbitrary.  A couple companies back we
were pretty heavy into cascading deletes and triggers, and I gained an
appreciation for them in terms of application development.

It seems that part of the impetus for stored procedures is the horror
 that DBAs have of random programmers issuing hack-laden SQL to their
 precious databases. My question: you've got backups, right? And any bad
 SQL should be taken care of before an app goes out the door. It's the
 programmer's responsibility to ensure that nothing he does can hack up
 the database. That includes parameterizing queries and vetting user data
 properly.


I think it's nice to have a full-fledged DBA if the biz can afford one.  I
tend to also worry about the other way round on this one, namely if the DBA
folks are getting their hands into application logic albiet stored
procedures.  That sort of arrangement is nothing short of disturbing to me.

Anyway, just some thoughts. Also, please consider PostgreSQL in addition
 to MySQL and MSSQL.


I've often discussed Postgre, but end up considering it for specific needs
more than anything.  Best use I ever had for it was a backend for Bind with
a php front-end

http://antdns.sourceforge.net/

Needed a little hacking to get it going, but it was pretty sweet!  We also
chose Postgre for a data warehouse at one company with a large dataset.  I
had nothing to do w/ that one though ;)

-nathan


[PHP] Re: using BOTH GET and POST in the same page.

2011-02-12 Thread Nathan Rixham

Ashim Kapoor wrote:

Dear All,

I am reading PHP5 and MySQL Bible. Chapter 7 of the book says that PHP can
use GET and POST in the SAME page! Also it says that we can use the SAME
variables in GET and POST variable sets and that conflict resolution is done
by variable_order option in php.ini Can some one write a small program to
illustrate the previous ideas?  It is not clear to me as to how to implement
this.


I noticed you've already received one response, so here's some more 
background info.


It's using $_GET and $_POST in the same script, not HTTP GET and HTTP 
POST. $_GET in PHP correlates to the query string parameters in the URL 
requested, $_POST in PHP correlates to form data which is POSTed to the 
server inside a message, with the type application/x-www-form-urlencoded.


One could say that $_GET and $_POST are named misleadingly, and that 
infact what you have is $_PARSED_QUERY_STRING_FROM_URL and 
$_POST_DATA_MAYBE .


The two are quite separate and can both be used at the same time.

HTML forms allow a method to be set, GET or POST, if GET then the form 
is treated like an URL construction template, if POST then it's treated 
like a message body construction template.


It's worth reading up on both HTTP and HTML Forms when using PHP, since 
PHP is a Pre Hypertext Processor and HTTP is the Hypertext transfer 
protocol, and HTML is the Hypertext markup language :)


Best,

Nathan

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



[PHP] Re: using BOTH GET and POST in the same page.

2011-02-12 Thread Nathan Rixham

Ashim Kapoor wrote:

Dear All,

I am reading PHP5 and MySQL Bible. Chapter 7 of the book says that PHP can
use GET and POST in the SAME page! Also it says that we can use the SAME
variables in GET and POST variable sets and that conflict resolution is done
by variable_order option in php.ini Can some one write a small program to
illustrate the previous ideas?  It is not clear to me as to how to implement
this.


I noticed you've already received one response, so here's some more 
background info.


It's using $_GET and $_POST in the same script, not HTTP GET and HTTP 
POST. $_GET in PHP correlates to the query string parameters in the URL 
requested, $_POST in PHP correlates to form data which is POSTed to the 
server inside a message, with the type application/x-www-form-urlencoded.


One could say that $_GET and $_POST are named misleadingly, and that 
infact what you have is $_PARSED_QUERY_STRING_FROM_URL and 
$_POST_DATA_MAYBE .


The two are quite separate and can both be used at the same time.

HTML forms allow a method to be set, GET or POST, if GET then the form 
is treated like an URL construction template, if POST then it's treated 
like a message body construction template.


It's worth reading up on both HTTP and HTML Forms when using PHP, since 
PHP is a Pre Hypertext Processor and HTTP is the Hypertext transfer 
protocol, and HTML is the Hypertext markup language :)


Best,

Nathan

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



[PHP] Re: Simplifying MySql queries

2011-02-12 Thread Nathan Rixham

Andre Polykanine wrote:

and  here  goes the question: is there a way to make these four in one
so  strictly  one  random  question  is  selected from all of the four
categories?


SELECT * FROM `CandidateQuestions` WHERE `Category` IN(1,2,3,4) ORDER 
BY RAND() LIMIT 4


note the limit 4, you'll be needing that to get back 4 rather than 1 :)

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



[PHP] Re: query strings and other delights

2011-01-13 Thread Nathan Rixham

kbai...@howlermonkey.net wrote:

Your turn! :-D


  $_GET

and if you do post.. (can you guess?)

  $_POST

usage:
  http://www.foo.org/item1/delivery.php?item=namecode=DATA

?php

 $_GET['item']; // == name
 $_GET['code']; // == DATA

Best,

Nathan

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



[PHP] Re: Rewriting string

2011-01-13 Thread Nathan Rixham

David McGlone wrote:

Hi everyone,

I think the subject is right, or somewhere close. Anyway I am trying to 
perform a little trickery here with links. In the following code you can see 
where I am trying to replace the link on the current page so it's not a link 
when on that page. I think I got the general idea of what I need to do as you 
can see in the code I just don't know how to accomplish it, if it's possible.



$categorys = array('home', 'services', 'gallery', 'about_us', 'contact_us', 
'testimonials');

foreach($categorys as $category){
$deadlink = $_GET['page'];
  
if ($deadlink == 'page') {


for a short answer, all you need to do is change the above line to:

  if($deadlink == $category)

and as a slightly colourful variant:

$categorys = array('home', 'services', 'gallery', 'about_us', 
'contact_us', 'testimonials');

foreach($categorys as $category){
  $temp = str_replace(_,  , $category);
  $_GET['page'] != $category  $temp = 'a href=index.php?page='. 
$category .''.$replace.'/a';

  echo li{$temp}/li . PHP_EOL;
}

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



Re: [PHP] Re: query strings and other delights

2011-01-13 Thread Nathan Rixham

kbai...@howlermonkey.net wrote:
...Holy cow... nothing to extract the query string, it's automatically 
part of the environment. So I just do work with the $_GET string, it's 
in there already... yikes.


yup

OK, so $_GET is an array keyed to keywords; plug in the key, out comes 
the value. What if I just want the entire string?


$_SERVER['QUERY_STRING']

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



[PHP] Re: query strings and other delights

2011-01-13 Thread Nathan Rixham

kbai...@howlermonkey.net wrote:

Your turn! :-D


just in case I totally misunderstood, and you simply have the string and 
want to rip out the component parts of the query string, then:


  ?php
$querystring = parse_url($url, PHP_URL_QUERY);
parse_str($querystring, $data);
print_r( $data );

Or similar, watch out for parse_str though as it'll swap out spaces and 
. for _ - which is nice.


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



Re: [PHP] Re: Rewriting string

2011-01-13 Thread Nathan Rixham

Admin wrote:
$categorys = array('home', 'services', 'gallery', 'about_us', 'contact_us', 
'testimonials');

If(in_array($_GET['page'], $categories))
{
echo 'lia href=index.php?page='.$_GET['page'].''.str_replace(_, 
,$_GET['page']).'/a/li';
}else{
echo 'li'.str_replace(_, ,$_GET['page']).'/li';
}

I normally never write someones code for them but you are just not getting it.
The above code works use it.


i assume you're joking - that code is simply going to give 6 list items 
all with the same value - $_GET['page']


please do check you know what you're talking about before you post.

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



Re: [PHP] Re: Rewriting string

2011-01-13 Thread Nathan Rixham

Nathan Rixham wrote:

Admin wrote:
$categorys = array('home', 'services', 'gallery', 'about_us', 
'contact_us', 'testimonials');

If(in_array($_GET['page'], $categories))
{
echo 'lia href=index.php?page='.$_GET['page'].''.str_replace(_, 
,$_GET['page']).'/a/li';

}else{
echo 'li'.str_replace(_, ,$_GET['page']).'/li';
}

I normally never write someones code for them but you are just not 
getting it.

The above code works use it.


i assume you're joking - that code is simply going to give 6 list items 
all with the same value - $_GET['page']


please do check you know what you're talking about before you post.


and ironically, that's wrong - it's only going to show it once, with or 
without a link, but isn't going to do what the OP wanted.


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



[PHP] Re: Craigslist Jobs

2011-01-11 Thread Nathan Rixham

Ethan Rosenberg wrote:

Dear List -

I am a NEWBIE, so .

How do I handle Craigslist postings? Is there anything special I should 
do?  Any advice for other web sites?


At this point I am talking about small jobs.

1] My payment.  Should I ask for something up front?  If so how much?


depends on the amount, how comfortable you are, and how comfortable they 
are, escrow is safer for larger amounts.



2] How do I protect myself so that I do not deliver code and not get paid.


pretty much the same way you protect yourself from not getting run over 
or robbed.



3] What is a reasonable hourly rate?


multiple factors here, a good starting point is to figure out how much 
you need to make an hour, add 20-40% on, then figure out how many hours 
it'll take you, multiply it all up and add on another 20-40%


All this depends on your skill level, if you can do the job, if the 
customer has the budget and so forth - just agree something you're both 
comfortable with.



4] Any other information that I should know?


Yes, you will get burned a few times, and have both good and bad 
experiences when you least expect them - the main thing is just to 
remember the clients are people, with a problem to solve, you're there 
to solve that problem in a cost effective manner, and ultimately your 
work has two values, the first is what you require to put food on the 
table, and the second is what the project is worth to the the client. If 
you land anywhere between the two of those, then you're doing well :)


Best,

Nathan

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



Re: [PHP] First PHP job

2011-01-10 Thread Nathan Nobbe
On Mon, Jan 10, 2011 at 2:55 PM, Steve Staples sstap...@mnsi.net wrote:

 On Mon, 2011-01-10 at 16:21 -0500, Paul M Foster wrote:
  On Mon, Jan 10, 2011 at 12:02:51PM -0600, Donovan Brooke wrote:
 
   Hello!, .. will try to keep this short!
   I've been a long time lurker but minimal poster. I made it a new years
   resolution to finally take on PHP jobs and now have my first one (with
 a
   completion date in a couple weeks!).
  
   I've been scripting in another language for many years and do know a
   thing or two.. but anticipate bothering the list a few times in the
 near
   future... hope that is fine with you all.
  
   I'm just about through Larry Ullman's PHP third edition that I
 started
   a couple days ago. Good book to start with I think, even for folks who
   have some kind of head start in Web Programming. I'm able to skim over
   a lot of it.
  
   I don't know how you all remain sane in dealing with quotes workarounds
   in echo/print statements, having to open/close PHP parsing using ?php
   ? all the time, and having to deal with array's for just about
   everything... but I'm sure I'll get used to it and it will become
 second
   nature at some point. ;-)
 
  That stuff's easy. I'm still trying to wrap my wits around the crazy way
  functions are handled in Javascript. I know of no other language which
  treats functions the way Javascript does.
 
  Wait until you get to PHP's automatic casting of strings to numbers under
  the proper conditions. You'll scratch your head for quite a while once
  you hit that one.
 
  Paul
 
  --
  Paul M. Foster
  http://noferblatz.com
 
 
 or the ($needle, $haystack) vs ($haystack, $needle)... i still get it
 screwed up... thankfully php.net/{function_name} is easy to use :P


php --rf function name

is also pretty handy.

-nathan


Re: [PHP] Command line PHP

2011-01-07 Thread Nathan Nobbe
On Fri, Jan 7, 2011 at 11:31 AM, Joshua Kehn josh.k...@gmail.com wrote:

 On Jan 7, 2011, at 12:34 PM, Daniel Brown wrote:

  On Fri, Jan 7, 2011 at 12:18, Joshua Kehn josh.k...@gmail.com wrote:
 
  Using another language more suited towards CLI / standalone (non-web)
 development would be easier. PHP at it's core is a templating language. I
 don't think it is as suited as say Python for developing standalone
 applications.
 
 One might argue that it depends on your mastery of and comfort
  with the language.  That in mind, the same is true of nearly any
  programming language.
 
 And thanks for reminding me of what PHP is at its core.  ;-P
 
  --
  /Daniel P. Brown
  Network Infrastructure Manager
  Documentation, Webmaster Teams
  http://www.php.net/

 My apologies. I just view PHP as a perfected web language, due to it's
 templating nature, while using it for other things (scripts, utilities,
 cron) is a misuse in my opinion.


shrug, you must not be too familiar with php then.  9 times out of 10 it's
the natural, perfect choice for a cli program.  there are situations where
you get past what php is ideal for on the cli, typically when you get into
heavy forking or require threading.


 It does completely depend on your mastery of the language. If you're very
 good with PHP and you don't often do non-web things it might not make sense
 to learn another language as well.


why bother learning 2 languages when 1 will suit most needs perfectly?  for
most folks who work with the web and a typical deployment environment like a
linux server, the second language of choice most likely would be a client
side one like javascript.

-nathan


Re: [PHP] Command line PHP

2011-01-07 Thread Nathan Nobbe
On Fri, Jan 7, 2011 at 11:54 AM, Joshua Kehn josh.k...@gmail.com wrote:

 On Jan 7, 2011, at 1:48 PM, Nathan Nobbe wrote:

 shrug, you must not be too familiar with php then.  9 times out of 10 it's
 the natural, perfect choice for a cli program.  there are situations where
 you get past what php is ideal for on the cli, typically when you get into
 heavy forking or require threading.


 It does completely depend on your mastery of the language. If you're very
 good with PHP and you don't often do non-web things it might not make sense
 to learn another language as well.


 why bother learning 2 languages when 1 will suit most needs perfectly?  for
 most folks who work with the web and a typical deployment environment like a
 linux server, the second language of choice most likely would be a client
 side one like javascript.

 -nathan


 You can't say that PHP is a more natural CLI choice then bash or Python.
 Maybe I'm using PHP too much for web development. Perhaps I am unfamiliar
 with it.


Um, I just did say it :P  It's pretty simple, I already know PHP, I don't
know Python or BASH well enough, obviously PHP is the best choice for a CLI
program in this case.  Yeah.., try writing a few scripts in PHP on the CLI,
you'll find it solid for many applications.


 Why bother learning other languages? Is this a joke? Why should someone
 stop learning *ever?** *Having a mastery of multiple languages can only
 enhance you.


No, it's not a joke.  The idea is why bother learning an language that will
score you little milage, in the context of the one you already know well.
 For example, if I'm a Web developer coding what CLI requirements I have in
PHP, then I might venture to learn something like Javascript before ever
touching Python.  So yes, having mastery of multiple languages can help you,
but it's best when these multiple languages don't overlap as much as PHP and
Python.

-nathan


Re: [PHP] Command line PHP

2011-01-07 Thread Nathan Nobbe
On Fri, Jan 7, 2011 at 12:53 PM, tedd tedd.sperl...@gmail.com wrote:

 At 12:16 PM -0700 1/7/11, Nathan Nobbe wrote:

 On Fri, Jan 7, 2011 at 11:54 AM, Joshua Kehn josh.k...@gmail.com wrote:

   Why bother learning other languages? Is this a joke? Why should someone
  stop learning *ever?** *Having a mastery of multiple languages can only
  enhance you.


 No, it's not a joke.  The idea is why bother learning an language that
 will
 score you little milage, in the context of the one you already know well.
  For example, if I'm a Web developer coding what CLI requirements I have
 in
 PHP, then I might venture to learn something like Javascript before ever
 touching Python.  So yes, having mastery of multiple languages can help
 you,
 but it's best when these multiple languages don't overlap as much as PHP
 and
 Python.

 -nathan


 nathan:

 I have to disagree with you a little-bit about this.

 If one knows the languages involved and realize their overlap, then they
 should have a better understanding of which language to use for what
 purpose. For example, which is better for styling CSS or Javascript? Both
 can do it, but one is the clear winner.


agreed, however, if im a skilled js programmer and need some rounded
corners, id probly just grab a library that leverages css to accomplish the
job before sitting down and really learning css.  or perhaps if my sql
skills aren't strong enough, i know i can get the job done w/ some extra
manipulation in php.  one should consider how much time will be spent
solving the current problem, how much time is available before the solution
must ship, and if it's beneficial to learn something entirely new just to
solve it when your current knowledge may provide a sufficient solution.

we're comparing php to bash/python here and frankly id like to know what the
main advantages of those languages over php for cli processing would be ..
marginal at best.  id hazard a guess that python supports threading tho :O

moreover, if i already know php, python is probly one of the last languages
i want to learn unless im considering abandoning php... the thought has
occurred to me ducks  id rather spend time learning something that runs
fast like brushing up on java or maybe C or C++, that way i'll get more
mileage for my time as i'll be more versatile with less overlap.  it's like
i could know 2 scripting languages w/ heavy overlap or 1 scripting language,
and one compiled language, that seems better from my perspective.  there are
always merits to knowing a shell language tho, and i've wanted to get
stronger with bash, but python .. i see it more as python OR php.

i worked on an asterisk app one time w/ a php front-end and many of the
asterisk hook scripts were written in bash.  this was a poor choice imo.  #1
we weren't leveraging code from the main app  #2 now i'm looking at running
mysql client through awk on the cli to get args into bash .. ouch.  give me
mysql_query(), lol.  much easier for anyone coming into the biz who knows
php to keep things consistent imo.

much of the gripe comparing php to python over the years is slowly fading
with the advent of new features of php, most notably closures.  once traits
are available im sure the multiple inheritance that python offers will be
less of an advantage over php's single inheritance paradigm.

-nathan


Re: [PHP] Command line PHP

2011-01-07 Thread Nathan Nobbe
On Fri, Jan 7, 2011 at 2:52 PM, tedd tedd.sperl...@gmail.com wrote:

 At 1:24 PM -0700 1/7/11, Nathan Nobbe wrote:

 On Fri, Jan 7, 2011 at 12:53 PM, tedd mailto:tedd.sperl...@gmail.com
 tedd.sperl...@gmail.com wrote:
 much of the gripe comparing php to python

 -nathan


 I try to stay away from snakes.


I have one tattooed on my back ;)

-nathan


[PHP] PHP Docs update

2011-01-06 Thread Nathan Rixham

To whoever did it,

it being http://docs.php.net/ - congrats, v nice, and v quick!

Best,

Nathan

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



Re: [PHP] Global or include?

2011-01-05 Thread Nathan Nobbe
On Wed, Jan 5, 2011 at 3:40 PM, Paul Halliday paul.halli...@gmail.comwrote:

 Say you have 10 or so scripts and a single config file. If you have
 main.php, functions1.php, functions2.php, functions3.php..

 Does is hurt to do an include of the config file in each separate
 script, even if you only need a few things from it,  or should you
 just specify what you want with a 'global' within each
 script/function?


touching on what Nicholas said this could be handled in OOP via the
singleton pattern, however there are ways of dealing w/ it in global
function land as well.

i see 4 immediate options
 . load config from each file (performance hit mitigated if config is a php
array and using opcode caching)
 . global variable
 . session storage
 . config fetching function w/ static variable

the last option is the one i'd like to describe since i think its the
cleanest, even if you have opcode caching enabled.  the function would look
something like this

function load_config()
{
  static $cachedConfig = null;

  if($cachedConfig !== null)
  {
// load file and store value(s) in $cachedConfig
  }

  return $cachedConfig;
}

now all you have to do is make load_config() available in all your files,
via something like require_once on the file which defines load_config().
 the result is the configuration will only be read once on a given page
load, thereafter its contents will come from memory.

this is actually very similar to the singleton approach in OOP.

-nathan


Re: [PHP] Global or include?

2011-01-05 Thread Nathan Nobbe
On Wed, Jan 5, 2011 at 4:27 PM, Nathan Nobbe quickshif...@gmail.com wrote:

 On Wed, Jan 5, 2011 at 3:40 PM, Paul Halliday paul.halli...@gmail.comwrote:

 Say you have 10 or so scripts and a single config file. If you have
 main.php, functions1.php, functions2.php, functions3.php..

 Does is hurt to do an include of the config file in each separate
 script, even if you only need a few things from it,  or should you
 just specify what you want with a 'global' within each
 script/function?


 touching on what Nicholas said this could be handled in OOP via the
 singleton pattern, however there are ways of dealing w/ it in global
 function land as well.

 i see 4 immediate options
  . load config from each file (performance hit mitigated if config is a php
 array and using opcode caching)
  . global variable
  . session storage
  . config fetching function w/ static variable

 the last option is the one i'd like to describe since i think its the
 cleanest, even if you have opcode caching enabled.  the function would look
 something like this

 function load_config()
 {
   static $cachedConfig = null;

   if($cachedConfig !== null)
   {
 // load file and store value(s) in $cachedConfig
   }

   return $cachedConfig;
 }

 now all you have to do is make load_config() available in all your files,
 via something like require_once on the file which defines load_config().
  the result is the configuration will only be read once on a given page
 load, thereafter its contents will come from memory.

 this is actually very similar to the singleton approach in OOP.

 -nathan


UMM, check that, the conditional should read

if($cachedConfig === null)
{
  // load config file :)
  $cachedConfig = $someValue; // ...
}

my bad, lol!

-nathan


Re: [PHP] Re: Do you trim() usernames and passwords?

2010-12-31 Thread Nathan Rixham

Tamara Temple wrote:


On Dec 28, 2010, at 2:11 PM, Joshua Kehn wrote:


Specifically:


Dotan Cohen wrote:

I seem to have an issue with users who copy-paste their usernames and
passwords coping and pasting leading and trailing space characters.


Users should not be copy-pasting passwords or usernames. Do not 
compromise a system to cater to bad [stupid, ignorant, you pick] 
users. If this is an issue then educate the users.


I'm sorry, but this is just bloody stupid. I keep my usernames and 
randomly generated, very long passwords in a password keeper. If you're 
not going to let me copy paste them into a web page, i'm just not going 
to ever use your application. Copy/pasting is something that happens on 
the *local* machine -- it never goes out to the net. By forcing people 
to type in their user names and passwords you are going to cause them to 
enter easily-remembered, and typically easily-crackable combinations. 
What is the possible logic for disallowing someone to paste in their 
usernames/passwords???


Tamara, you're missing half the context, the whole point was don't send 
username and password combo's in plaintext via email to users (thus 
forcing them to copy and paste from email) - this point was made but 
then that context has been stripped from the above email, obviously 
copy+pasting from a password keeper and such like is totally fine..



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



Re: [PHP] Re: Do you trim() usernames and passwords?

2010-12-31 Thread Nathan Rixham

Tamara Temple wrote:
Sorry, I was mislead by your use of the phrase Users should not be 
copy-pasting passwords or usernames above. I'd love to hear what you 
think is an alternative to identifying with web app that keeps track of 
information about someone that is more secure.


client side ssl certificates, they force http+tls (thus encryption over 
the wire and no chance of middleman attacks) and no usernames or 
passwords need to be passed, as you identify people by the public key 
held in their certificate, the TLS process ensures they have the private 
key.


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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Nathan Rixham

Ethan Rosenberg wrote:
FYI [to all the list] -- I thank all for their input.  I only needed US 
phones, and I am forcing the user of the form to conform to xxx-xxx- 
as the input format.


out of interest, why are you forcing you're users to conform to that 
input format? you could simply strip all non-numeric chars then format 
how you like to save, thus giving users a looser, more friendly, experience.


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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Nathan Rixham

Ethan Rosenberg wrote:

At 07:11 AM 12/31/2010, Nathan Rixham wrote:

Ethan Rosenberg wrote:
FYI [to all the list] -- I thank all for their input.  I only needed 
US phones, and I am forcing the user of the form to conform to 
xxx-xxx- as the input format.


out of interest, why are you forcing you're users to conform to that 
input format? you could simply strip all non-numeric chars then format 
how you like to save, thus giving users a looser, more friendly, 
experience.

+
Nathan -

This expression will be used to search a database which will contain 
patient data resulting from medical research.  At the initial visit a 
medical record number will be assigned to the patient.  Other 
information will be collected at that point; eg,  the telephone number. 
At subsequent visits, the patient will be referenced by his/hers medical 
record number.  If the patient either forgot their clinic card, or 
cannot remember their medical record number, a search will be 
performed.  One of the many parameters that can be used in the search is 
the phone number. It is easier if all the data has a fixed format.  The 
form for  the initial visit will use a regex that will validate the 
phone number. As  the research will be performed in the US, only US 
numbers have to be validated.


Ethan,

I think you misunderstand, I'm saying that regardless of which format 
you use within the system, users could enter phone numbers as 
1231231234 123 123 1234 123-123 1234 or any variant they like, 
that's completely orthogonal to how you validate and save the data, in 
all of those cases all you need to do string non-numeric chars to 
validate, you may also find your indexes work that bit quicker storing 
numbers rather than specially (and needlessly) formatted string.


Likewise on the way back out, when presenting the numbers to users, all 
you need to do is string format them.


Follow?


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



[PHP] Re: Hot Topics

2010-12-30 Thread Nathan Rixham
Pretty sad day when you have to apologise for being a human on an open 
list to which you've contributed heavily for many many years.


apology not accepted from me Dan, you've nothing to apologise for, and 
anybody who doesn't like to read a bit of banter between people on a 
list can just avert their eyes - it was hardly 4chan grade trolling!


Best  happy new year to you,

Nathan

Daniel Brown wrote:

First, I have to admit that what I did was wrong.  I had assumed
(ASS-umed) that the other party in a discussion under a different
thread would understand and appreciate the irony of my email in reply
to his inappropriate message.  Those of you who were barraged with the
fallout know what I mean.  Unfortunately, it was not well-received by
the other person, which led to even further flaming and trolling.
While I had tried both on- and off-list to urge the other party to
move the discussion from the public forum to a private, one-on-one
conversation, it was ignored and actually seemed to exacerbate the
situation.  For my part in that, I just wanted to send my general
apologies to those bombarded with an unnecessary and somewhat
illogical series of emails.  If being married has taught me anything,
it's that it's better to just apologize and move on, regardless of
who's right or wrong.  And if being married has taught me anything
else, it's that, at least in this house, I'm always wrong.  So
sorry for the unnecessary banter.

Moving on, those of you who have been on the list for several
years may recall when I was running the ListWatch and PostTrack
system, which would send a weekly summary of the list's activities at
the time.  Before stopping it (it was on a server that burned out, and
I just never put it back online), I had added a topic tracker as well,
which would give the percentage of activity for a given topic, as well
as the ratio of its discussion versus all messages to the list.
Several people have asked if/when it would be coming back online, so
I'm contemplating bringing it back beginning with the first week of
January (next week).  Does anyone have any thoughts on that, or any
ideas for other interesting metrics they'd like to see?  I'm
particularly interested in the opinions of folks who recall the old
system, but any opinions and ideas are more than welcome.

If you'd rather send it to me directly instead of on the list, feel free.

Happy early New Year, all.




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



[PHP] Re: Do you trim() usernames and passwords?

2010-12-28 Thread Nathan Rixham

Dotan Cohen wrote:

I seem to have an issue with users who copy-paste their usernames and
passwords coping and pasting leading and trailing space characters.


Don't trim or limit the range of input characters, but far more 
importantly /don't send passwords in clear text/, indeed don't generate 
passwords at all, let users enter there desired password, then they 
won't be copy and pasting them ;)


ps: if unavoidable, then give some advice on login failure like 
passwords are case sensitive, check you don't have caps lock on and 
that you haven't included any additional spaces.


Best,

Nathan

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



Re: [PHP] Re: Do you trim() usernames and passwords?

2010-12-28 Thread Nathan Rixham

Joshua Kehn wrote:

Trim usernames but not passwords.


agree. nice catch, I was thinking about passwords specifically and 
forgot usernames was in the topic too!




On Dec 28, 2010, at 2:57 PM, Nathan Rixham wrote:

Dotan Cohen wrote:

I seem to have an issue with users who copy-paste their usernames and
passwords coping and pasting leading and trailing space characters.

Don't trim or limit the range of input characters, but far more importantly 
/don't send passwords in clear text/, indeed don't generate passwords at all, 
let users enter there desired password, then they won't be copy and pasting 
them ;)

ps: if unavoidable, then give some advice on login failure like passwords are 
case sensitive, check you don't have caps lock on and that you haven't included any additional 
spaces.

Best,

Nathan

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







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



[PHP] Re: Do you trim() usernames and passwords?

2010-12-28 Thread Nathan Rixham

Dotan Cohen wrote:

On Tue, Dec 28, 2010 at 21:57, Nathan Rixham nrix...@gmail.com wrote:

Don't trim or limit the range of input characters, but far more importantly
/don't send passwords in clear text/, indeed don't generate passwords at
all, let users enter there desired password, then they won't be copy and
pasting them ;)

ps: if unavoidable, then give some advice on login failure like passwords
are case sensitive, check you don't have caps lock on and that you haven't
included any additional spaces.



I'm toying with the idea of having the passwords hashed twice: they're
already in the database hashed, and javascript hashes them on the
client before sending them over, but I'm thinking about sending an
additional salt to the client to hash the hashed passwords with salt,
and that's what is sent back. This way, each login is done with a
different hash of the password so an attacker cannot simply capture
and reuse the hashed password.


That would possibly address some man in the middle attacks, however it'd 
be much easier and more secure to simply have all logged in 
functionality over http+tls (https://) which will ensure encryption over 
the wire, and it's peer to peer thus impossible for anything to even be 
in the middle.


Best,

Nathan

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



Re: [PHP] Re: Do you trim() usernames and passwords?

2010-12-28 Thread Nathan Rixham

Joshua Kehn wrote:

On Dec 28, 2010, at 3:18 PM, Dotan Cohen wrote:


I'm toying with the idea of having the passwords hashed twice: they're
already in the database hashed, and javascript hashes them on the
client before sending them over, but I'm thinking about sending an
additional salt to the client to hash the hashed passwords with salt,
and that's what is sent back. This way, each login is done with a
different hash of the password so an attacker cannot simply capture
and reuse the hashed password.

But before all that goes on, I have to decide what to do about leading
and trailing spaces.


Toy with it and discard it. Client side hashing / salting is not a good idea. A 
much better alternative is to use SSL.


indeed, and on reflection, if you're putting this much effort in to it, 
and security is a worry, then forget username and passwords, and issue 
each user with a client side RSA v3 certificate and identify them via 
the public key of the cert.


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



Re: [PHP] Re: Do you trim() usernames and passwords?

2010-12-28 Thread Nathan Rixham

Dotan Cohen wrote:

On Tue, Dec 28, 2010 at 22:30, Joshua Kehn josh.k...@gmail.com wrote:

indeed, and on reflection, if you're putting this much effort in to it, and
security is a worry, then forget username and passwords, and issue each user
with a client side RSA v3 certificate and identify them via the public key
of the cert.

I just realize that this would also completely solve your trim() problem!



Hello, Dotan? Hi, we haven't spoken in a full week now that we don't
have the trim problem. But I reinstalled Windows and wiped the drive,
now I can't log in. Can you help me?



that's what pkcs12 was invented for, just issue another certificate / 
key pair.


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



Re: [PHP] how would I do this?

2010-12-27 Thread Nathan Nobbe
On Mon, Dec 27, 2010 at 2:13 PM, David McGlone da...@dmcentral.net wrote:

 Hi all,

 I am trying to make the link in this code not show the underscore and I
 can't
 figure out how I could do it. I've tried various different things I thought
 would work. I've tried things like lawn_maintenance= lawn maintenance,
 I
 tried concatinating lawn . maintenance and various other things. The
 examples above both produce just the word lawn

  here's the code I have so far:

 $services = array(lawn_maintenance, core_areation, over_seeding,
 hedge_trimming, mulch_installation, natural_debris_removal,
 leaf_cleanup_removal, snow_plowing);


 foreach ($services as $service){

 echo ulliraquo; a
 href=index.php?page=$service$service/a/li/ul;
 }


just clean up the array definition:

$services = array('lawn_maintenance', 'core_areation', 'over_seeding',
'hedge_trimming', 'mulch_installation', 'natural_debris_removal',
'leaf_cleanup_removal', 'snow_plowing');


 Could anyone give me a hand? Obviously I don't understand arrays very well
 :-/


looks more like it's the strings you're struggling with ;)

-nathan


Re: [PHP] String passed to object constructor turning into aninstance of that object?

2010-12-16 Thread Nathan Nobbe
On Thu, Dec 16, 2010 at 3:21 PM, Kris Deugau kdeu...@vianet.ca wrote:

 Nathan Nobbe wrote:

 Why not test for the type of $name at each point of interest in the
 SelectBoxOption
 constructor?  If you're passing a string value to the constructor it
 almost
 has to be getting changed by the Tag constructor, right ?

  class SelectBoxOption extends Tag {
   function SelectBoxOption($name, $value, $selected=false) {

 var_dump(is_string($name));

 parent::Tag(option, $name);

 var_dump(is_string($name));


 Ah, that gives...  well, it slightly alters the confusion.

 Using var_dump(is_string($name)) gives...  two results?

 bool(true)
 bool(false)

 And dumping $name itself gives:

 string(8) Abegweit
  object(SelectBoxOption)#65 (5) { [attributes]= array(1) { [0]=
 object(TagAttribute)#66 (3) { [name]= string(5) value [value]=
 string(1) 4 [hasValue]= bool(true) } } [tagContent]= string(8)
 Abegweit [tag]= string(6) option [showEndTag]= bool(false)
 [children]= array(0) { } }

 O_o

 Just to confirm, I checked a test instance of the site on CentOS 4, with
 PHP 4.3, and I get one bool(true) for each option - not two as is
 happening with PHP 5.2.


probly something screwy going on w/ the old style of naming constructors.  2
things,

1. can you post the Tag constructor as it reads now?
2. try modifying Tag  SelectBoxOption to have __construct() instead of
Tag()  SelectBoxOption(), then call parent::__construct() from inside
of SelectBoxOption::__construct(); see if that clears up your problem under
5.2 (read: this will only be a partial solution as it only addresses one
child of Tag).


 -kgd

 (I haven't worked with PHP for quite a while, and I never really spent a
 lot of time getting deep into complex data structures and object hierarchies
 like this when I was using it.  But this behaviour does NOT match what I
 know of passing values and object references around in any other language.)


Probly because the term 'reference' in php means something rather different
than it does in say java for example.


Re: [PHP] String passed to object constructor turning into an instance of that object?

2010-12-16 Thread Nathan Nobbe
On Thu, Dec 16, 2010 at 4:04 PM, Kris Deugau kdeu...@vianet.ca wrote:

 Nathan Nobbe wrote:

 probly something screwy going on w/ the old style of naming constructors.
  2
 things,

 1. can you post the Tag constructor as it reads now?


 function Tag($tag='', $tagContent='') {
  $this-tagContent = $tagContent;
  $this-tag = $tag;
  $this-showEndTag = false;

  $this-attributes = array();
  $this-children = array();

 }


seems innocuous ..



  2. try modifying Tag  SelectBoxOption to have __construct() instead of
 Tag()  SelectBoxOption(), then call parent::__construct() from inside
 of SelectBoxOption::__construct(); see if that clears up your problem
 under
 5.2 (read: this will only be a partial solution as it only addresses one
 child of Tag).


 Mmm.  I hoped this would help, but all it seems to have done was cascade
 errors across the rest of Tag's object children.  :(


to be expected, but did it fix the problem w/ SelectBoxOption?


 Copying the old constructor back in resolved that, but I'm not sure whether
 that reintroduces the root problem.


 Other objects derived from Tag seem to work just fine;  I came into this
 chunk of the code trying to find out why a SelectBoxOption didn't seem to
 have a toString function - and then why trying to access what should be the
 value and name the same way as with other objects derived at some level from
 Tag blew up instead of working happily.

 I'll try converting all of the constructors to your recommendation as
 above, but given that the problem is only happening with this one class, I'm
 not sure that will do much.


hopefully that clears it up .. and hopefully you're using version control :D

-nathan


Re: [PHP] String passed to object constructor turning into aninstance of that object?

2010-12-16 Thread Nathan Nobbe
On Thu, Dec 16, 2010 at 3:21 PM, Kris Deugau kdeu...@vianet.ca wrote:

 Nathan Nobbe wrote:

 Why not test for the type of $name at each point of interest in the
 SelectBoxOption
 constructor?  If you're passing a string value to the constructor it
 almost
 has to be getting changed by the Tag constructor, right ?

  class SelectBoxOption extends Tag {
   function SelectBoxOption($name, $value, $selected=false) {

 var_dump(is_string($name));

 parent::Tag(option, $name);

 var_dump(is_string($name));


 Ah, that gives...  well, it slightly alters the confusion.

 Using var_dump(is_string($name)) gives...  two results?

 bool(true)
 bool(false)


so you put one check before the call to parent::Tag()  one directly after
right?  That means *somehow* $name is getting set to an instance of
SelectBoxOption in the parent constructor which makes little to no sense..
especially after looking at implementation from your later post.  Main
things are $name is local in the child constructor and there is no pass by
reference on the $name parameter in the parent constructor definition.

if this code runs w/o error on your 5.2 box, then there's something spurious
going on in that old library;

?php
class Tag
{
function Tag($sTag='', $sValue='')
{
$this-_sTag = $sTag;
$this-_sValue = $sValue;
}
}

class Child extends Tag
{
function Child($name)
{
var_dump($name);
parent::Tag('option', $name);
var_dump($name);
}
}

$oChild = new Child('content');
?

expected output:

string(7) content
string(7) content

I'd still recommend moving to the php5 notation throughout the library,
especially if doing that fixes the problem w/ SelectBoxOption.  This
shouldn't break any client code, since clients should all be calling new
Class() and not be explicitly invoking the php4 style constructors.  The
php4 style constructors should only be getting called explicitly from within
the library itself.

-nathan


Re: [PHP] Does ReflectionMethod::setAccessible() do anything?

2010-12-16 Thread Nathan Nobbe
On Thu, Dec 16, 2010 at 6:37 PM, David Harkness
davi...@highgearmedia.comwrote:

 According to the manual page for setAccessible() [1] the feature is
 available with 5.3.2, and I'm running

5.3.2-1ubuntu4.5 with Suhosin-Patch (cli) (built: Sep 17 2010 13:49:46)

 so I should be good to go. However, even the simplest test to make a
 protected or private method accessible fails.

php  class Foo { protected function bar() { echo foobar\n; } }
php  $m = new ReflectionMethod('Foo', 'bar');
php  $m-setAccessible(true);
php  $foo = new Foo();
php  $foo-bar();


you just have to invoke the function from the context of the
ReflectionMethod instance

?php
class Foo { protected function bar() { echo foobar\n; } }
$m = new ReflectionMethod('Foo', 'bar');
$m-setAccessible(true);
$m-invokeArgs(new Foo(), array());
?

-nathan


  1   2   3   4   5   6   7   8   9   10   >