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


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


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


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


Re: [PHP] Singleton with variable parameters

2010-12-15 Thread Nathan Nobbe
On Wed, Dec 15, 2010 at 2:11 PM, Sebastian Detert php-maill...@elygor.dewrote:

 Hi guys,

 I am trying to generate an abstract Singleton class for use in arbitrary
 classes, like

 class Foo extends Singleton {}

 and generate a new class with Foo - getInstance();


Until traits release I think you'll find this painful as any class that
extends Singleton must now have extra functionality imbued via interfaces
and composition.

You will probly prefer to use a registry, something like
Registry::getInstance('classname', array('parameters'));

Even if you go with an abstract base class you will want an array of
instances internally.

How can I manage to use this with an unkown number of parameters like Foo -
 getInstance('a', 'b'); ?


yes, func_get_args()  call_user_func_array() however, fyi, these are very
slow.


 Something like self::$instance = call_user_func (array(static ,
 __construct), func_get_args()); instead of self::$instance = new self;
 doesn't work and an eval() is too slow.


if performance is a concern why not use setters to establish state on all of
your classes and keep the getInstance method down to 0 params.  As long as
your singletons aren't immutable this should work just fine.

-nathan


Re: [PHP] Scalable Vector Graphics with PHP

2010-12-09 Thread Nathan Nobbe
On Thu, Dec 9, 2010 at 4:55 AM, sudarshana sampath 
sudarshanasamp...@gmail.com wrote:

 Hi,

 We are going add a topology view to our Network Management System.
 Our Network Management System is based on PHP, CakePHP, jQuery and other
 web
 related tools(middle tier written using C++).

 So we are going to work with Scalable Vector Graphics.

 We are looking for the best solution for doing that.

 Are there any extensions, plugins, frameworks available for SVG related
 things ?


not sure exactly what youre trying to accomplish, but obviously you could
use any number of vector programs over the cli from php.

you might also have a peak at the cairo library which php allegedly supports
(ive never tried it myself).

http://us.php.net/manual/en/intro.cairo.php

-nathan


Re: [PHP] new keyword combined with other things...

2010-12-08 Thread Nathan Nobbe
On Wed, Dec 8, 2010 at 12:26 PM, Tommy Pham tommy...@gmail.com wrote:

  -Original Message-
  From: David Harkness [mailto:davi...@highgearmedia.com]
  Sent: Wednesday, December 08, 2010 10:46 AM
  To: Paul M Foster
  Cc: php-general@lists.php.net
  Subject: Re: [PHP] new keyword combined with other things...
 
  On Wed, Dec 8, 2010 at 9:31 AM, Paul M Foster
  pa...@quillandmouse.comwrote:
 
   I agree. My advice for SQL is always to learn SQL rather than use a
   bunch of active record functionality. But I'm sure people think I'm
   just a curmudgeonly old turd. ;-}
  
 
  Yes, absolutely learn SQL so you understand what's happening under the
  covers, AND then use a framework to abstract much of it away. I cannot
  speak to ActiveRecord, but ORM frameworks like Hibernate in the Java
  world save countless man-hours of work every day, time that can be spent
  on making better applications.
 

 Last time I checked, there isn't an equivalent of Hibernate for PHP. :)


pretty sure doctrine is as close as it gets w/ its DQL

-nathan


Re: [PHP] How can I call GD's imagepng() directly from my class?

2010-12-06 Thread Nathan Nobbe
On Mon, Dec 6, 2010 at 5:01 PM, Daevid Vincent dae...@daevid.com wrote:

 I have a class that does some massive computations to compute a LOPA
 (layout of passenger aircraft).

 I currently render it in an HTML table with little seats. I want to now
 make this using GD so I can show entire fleets of aircraft on one page.

 Inside my LOPA.class.php I have this method:

public function render_image()
{
$my_img = imagecreate( 200, 80 );
$background = imagecolorallocate( $my_img, 0, 0, 255 );
$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
imagestring( $my_img, 4, 30, 25, Test Image, $text_colour
 );
imagesetthickness ( $my_img, 5 );
imageline( $my_img, 30, 45, 165, 45, $line_colour );

header( Content-type: image/png );
header('Content-Length: ' . strlen($my_img));
imagepng( $my_img );

imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );
}


 And I'm trying to call it from a PHP page like so:

 img src=?php $my_lopa-render_image(); ? alt=Image created by a PHP
 script width=200 height=80

 But it doesn't show the picture. :\

 If I take the contents of that function and dump it into a gdtest.php
 file and call it like this however, it does work:

 img src=images/gdtest.php alt=Image created by a PHP script
 width=200 height=80

 So what am I doing wrong above that I can't just call it from my class?


Your approach with the class should show as src= on your rendered web page
since the output from the function is binary meant for the browser, read:
not meant as content for an HTML attribute.

The later however is fine, since its text which references a php page.  What
happens when that is sent to the browser is it invokes images/gdtest.php on
your server, which outputs the binary directly to the browser.

If you want to use the class, you should do as your second example for the
tag itself, then inside of images/gdtest.php instantiate the class and call
the method.

gdtest.php

?php
 $oImgRenderer = new LOPA(); // or whatever your class is called
 $oImgRenderer-render_image();
?

-nathan


Re: [PHP] How can I call GD's imagepng() directly from my class?

2010-12-06 Thread Nathan Nobbe
On Mon, Dec 6, 2010 at 5:26 PM, Daevid Vincent dae...@daevid.com wrote:


 I got a little 'hack' further, but not loving it. Maybe I'll move the image
 to a $_SESSION variable and then have the gdtest.php pull it and echo it
 that way


well i think you may be in the right direction, however, id be interested to
see what others on the list think about this particular approach.
 personally, i wouldnt store an image in the session.. but i would certainly
provision a temporary directory inside the webroot where you could put these
images.

perhaps if the images are tied to sessions, throw cleanup in a custom
session cleanup cron, or queue the images for deletion when the user logs
out.  seems to me like the session is an area of abuse in many php apps ive
seen.  even though the standard store is file based, i would still recommend
a separate store for images.



public function render_image()
{
$my_img = imagecreate( 200, 80 );
$background = imagecolorallocate( $my_img, 0, 0, 255 );
$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
imagestring( $my_img, 4, 30, 25, Test Image, $text_colour
 );
imagesetthickness ( $my_img, 5 );
imageline( $my_img, 30, 45, 165, 45, $line_colour );

 ob_start();
 header( Content-type: image/png );
header('Content-Length: ' . strlen($my_img));
imagepng( $my_img );
 $final_image_data = ob_get_contents();
ob_end_clean();

imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );

 echo
 'data:image/png;base64,'.base64_encode($final_image_data);
}

 img src=?php $my_lopa-render_image(); ? width=200 height=80


i dunno, why not just have something a bit simpler, where you generate an
image and store it to disk.  the function could return the path where the
image was saved.  then when the browser loads that resource php doesnt even
fire up, the webserver just sends back the image directly.

not sure on whether you would pass in the location or if you would have
internal logic cook up the path, but im sure you could determine that based
on the rest of the code .. lets suppose your class computes it internally,

something like

?php
class LOPA
{
  private function get_temp_path()
  {
 // some session specific logic to cook up a temporary path
 // something relative to the web root ...
  }

  public function render_image()
  {
$my_img = imagecreate( 200, 80 );

$background = imagecolorallocate( $my_img, 0, 0, 255 );
$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );

imagestring( $my_img, 4, 30, 25, Test Image, $text_colour);
imagesetthickness ( $my_img, 5 );
imageline( $my_img, 30, 45, 165, 45, $line_colour );

// now saving to a temp location inside the webroot
$temp_path = $this-get_temp_path();
imagepng( $my_img, $temp_path );

imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );

// returning path to temp location
return $temp_path;
  }
}
?

!-- now this just has a path which points right back to an image, served
directly --
img src=?php $my_lopa-render_image(); ? width=200 height=80

-nathan


Re: [PHP] Iterators.

2010-12-03 Thread Nathan Nobbe
On Fri, Dec 3, 2010 at 6:09 AM, Richard Quadling rquadl...@gmail.comwrote:

 Hi.

 OK. I'm stuck. I just can't work this out.

 I like SPL. I like the re-usability. It seems right. But I just can't
 work it out.

 I want to read through a file system, looking for files of a particular
 type.

I want to ignore and not traverse any folder with a specific name
 anywhere in the directory tree.
 I want to examine the contents of the file with a set of regular
 expressions and call a closure for each match for each regex which
 will replace and replace the file with the amended one.
 I want to get a list of the files altered along with which regex and
 the number of changes.


That could work with DirectoryIterator, a subclass thereof, or a combination
of DirectoryIterator and FilterIterator.



 The part I'm really stuck on is working out what elements of the SPL
 fit my issue the best and what bits I have to implement myself, with
 regard to the file system iteration and filtering.


You have a few options as I mentioned above.  Depends on whether you want to
encapsulate the logic you're mentioning or if you just want to use it in one
place.

The simplest way to go is DirectoryIterator, driving the iteration via
foreach, and your custom logic goes inside the body of the foreach.

foreach(new DirectoryIterator('.') as $oFile)
{
// custom, one-off logic here
// ex. skip directories w/ a given name
if($oFile-isDir()  $oFile-getFilename() == 'LeaveMeAlone')
  continue;
}

Issue here is the logic portion is not very re-usable.  You could easily
move the logic into a subclass though if you want to have re-usable logic.
 Most likely this will end up in the current() function, however, you may
want to consider dividing up the logic between a DirectoryIterator subclass
and a FilterIterator implementation.

FilterIterator lends itself to the 'should I operate on this node' question,
so when you're talking about looking for files of a certain type and folders
of a certain name, that sounds like it should go in a FilterIterator.
 However, at a cursory glance, if you want to skip entire sets of children
based on the name of a given directory, you'll likely need to iterate a
RecursiveDirectoryIterator yourself of subclass RecursiveIteratorIterator.

For the other part, w/ the closure, changing files and tracking which files
have been changed, that sounds best for a DirectoryIterator subclass.  And
if you're planning on handling multiple directories, w/ nested children, go
for a RecursiveDirectoryIterator.


 The tree is pretty large - just over 5,000 files with 5,700
 directories. The deepest file is 12 levels down.


 Now I know someone could supply a solution not using the SPL. I've got
 one of those. But trying to use the SPL just seems to awkward. Too
 many choices. Too many things with the same name

 Iterator, RecursiveIterator, RecusiverIteratorIterator.


Once you've messed with the classes for a bit, the choices become much more
natural and obvious, I too was overwhelmed by the sheer number of classes
when I first had a look.


 An Iterator suggests that it can work on a simple array ($argv for
 example). A non SPL variant would be foreach().
 A RecursiveIterator suggests it can iterator recursively on nested
 data (a file system for example). Using a function which uses
 scandir() and calls itself for a directory would look like a recursive
 iterator.

 So what does a RecursiveIteratorIterator do? Documentation says Can
 be used to iterate through recursive iterators..


The RecursiveIteratorIterator is best thought as a tool to 'flatten' out
a hierarchal data structure.  So imagine having 1 foreach block and every
node in the tree magically gets driven through it at some point.  Without
RecursiveIteratorIterator you have to be bothered to make calls to the
hasChildren() / getChildren() methods of the RecursiveIterator, and then
iterate though the child Iterators yourself.  RecursiveIteratorIterator just
packages that logic up in a standard way.


 But that sounds daft. The RecursiveIterator is the handling the
 parent/child/tree navigation (isn't it - if not why not?)


 The name really doesn't help me to understand what's going on or what its
 for.


The docs are a little rough, but manageable after you've messed w/ the
classes a bit, but I know what you mean.


 Is there any place that can describe the SPL in a different way.


Head to the homepage of the original SPL docs,

http://www.php.net/~helly/php/ext/spl/

then search for Some articles about SPL these are quite useful when
getting started w/ the Iterators.

I know it's probably just me, but it really seems like I'm only just
 scratching the surface. And not really getting anywhere.


I mean, I don't know anything but am glad to help where I can.  Not everyone
cares for Iterators, but they're a great way to package re-usable logic and
manage OO collections.  Of course I doubt PHP will ever have type safe
collections :O

Here's a quick 

Re: [PHP] Procedural Autoloader?

2010-11-22 Thread Nathan Nobbe
On Mon, Nov 22, 2010 at 2:24 PM, Daniel P. Brown
daniel.br...@parasane.netwrote:

 On Mon, Nov 22, 2010 at 15:37, Jason Pruim li...@pruimphotography.com
 wrote:
  Hey Everyone!
 
  Fresh off my problem with functions and arrays I come across something
 that
  I can't seem to find currently... The autoloader function that is in PHP
 5+
  works on classes... But I'm not finding anything that would do the same
  thing on the procedural end... Such as I have a folder typically called
  includes in my projects where I place all my function files... I would
 LOVE
  to use the autoloader to be able to just load them on demand... But in my
  quick searching/thinking I haven't found away too... So I thought I would
  see if anyone had invented that wheel yet before I go and try and do it
 my
  self :)
 
  I may also have a misunderstanding of how it is supposed to work since I
  don't truly understand OOP I've always done procedural...
 
  Any help on this one would be greatly appreciated it! :)

 There's no such thing, Prune.  Autoloaders are for classes, and
 the only way you could have it work for functions would be to catch
 the error in the core and handle it at a lower level than your scripts
 (modified core or extension), because the error generated for an
 undefined function isn't a catchable fatal.  Alternatively, you
 *could* write a function wrapper that utilizes function_exists() and
 the like, then rewrite all of your code to use that wrapper but
 how much sense does that make?  ;-P


Shrug, if you want to really be dirty about it, you could just put a 'class'
atop each file of functions.

?php
class IWishTheseFunctionsWereOOInstead {} // :P

function firstProceeduralFunc() {
 // ..
}
?

-nathan


Re: [PHP] How to protect the source code.

2010-11-19 Thread Nathan Nobbe
On Fri, Nov 19, 2010 at 3:07 PM, Tamara Temple tamouse.li...@gmail.comwrote:


 On Nov 19, 2010, at 3:39 PM, Hans Åhlin wrote:

  Does any one know if there is any way for me to protect my source code
 without the requirement of a extension being installed on the server?
 i.e encryption, obfusicator, script library, compile the code.


 Perhaps it's just me, but I'm completely missing the point of this. How is
 someone going to get your code off of a server?


most likely op intends to distribute code to others which they do not want
to be recognizable yet still be runnable.

one way to cope with this as mentioned before on this list is to provide a
thin api client in non-obfusticated form for an api which houses most of the
proprietary logic on a remote server.

most (all?) of the proposed solutions require installations of non-standard
extensions or runtime environments on the server for clients and that
typically is not realistic.

-nathan


Re: [PHP] Shopping cart question

2010-11-07 Thread Nathan Nobbe
On Fri, Nov 5, 2010 at 5:51 PM, Tommy Pham tommy...@gmail.com wrote:

  -Original Message-
  From: Nathan Nobbe [mailto:quickshif...@gmail.com]
  Sent: Friday, November 05, 2010 11:40 AM
  To: Jack
  Cc: PHP
  Subject: Re: [PHP] Shopping cart question
 
  On Fri, Nov 5, 2010 at 12:30 PM, Jack jacklistm...@gmail.com wrote:
 
   Hello All,
  
  
   I'm looking to build a DB with items that are considered more of a
   catalog on one side of a website, and then provide those same items
   including the same images, descriptions etc. to a shopping cart.
  
   I don't want to re-invent all of the basic shopping cart functionality
   and I'm not sure I want to use something like OScommerce and inject
   the data into it at the same time as putting data into our database
   that we are writing.
  
  
   I was hoping someone out there has some suggestions, or even a cart
   module that would allow me to easily integrate into.
  
 
  One recommendation I can give you is to spend some time determining if
  Magento works for you.  This is a conventional platform written on top of
  Zend Framework.  OScommerce, and a derivative, ZenCart are ancient, and
  there are many nasty things about the programming practices, most
 notably,
  the 'view' layer, which is markup intermingled with logic .. its pretty
 bad.
 
  Magento is robust, and has a feature set that makes OScommerce look like
 it
  shipped from the third world.  That said it may be overkill as well -
 just my
  2c.
 
  -nathan

 Or look at opencart.  It's based on MVC and jquery (1.3.2 ?) so you'll get
 some rich UI.  The DB structure is very similar to oscommerce.


I've finally had a few minutes to look around Opencart.  the framework is
custom, and doesn't appear to be as robust as some of the more popular ones
I've come to enjoy, but there is a silver lining...

I still can't say whether I'll like it or not, but after just digging around
for a bit, it already feels more approachable than Magento.  My hope is I
can hop in and wire this up to associate its schema to a third party
inventory and get order integration in place as well.

I've spent a little time digging into Magento, and while it seems do-able,
the completion date is no where in sight.

nice tip Jack!

-nathan


Re: [PHP] read smb drive

2010-11-05 Thread Nathan Nobbe
On Fri, Nov 5, 2010 at 9:48 AM, Steve Staples sstap...@mnsi.net wrote:

 Hey guys (and gals)

 I am writing something that needs to connect to a SMB server... can this
 be done easliy?

 I copied a sample code from php.net that used the system() command and
 mounted the SMB to a /mnt/tmp partion, and technically, it works the
 problem is, is that mount has to be run as root...

 is there a way to put the mount/unmount commands into an allowed
 command?   i supposed, the other problem is, is waht if this is on a
 windows machine?

 i dont really want to mess with permissions too much, since this will
 have to be portable from linux to windows...   any help would be
 appreciated...


is there any reason the php application code has to be responsible for
mounting the network drive?

typically this is an os-level responsibility.

-nathan


Re: [PHP] read smb drive

2010-11-05 Thread Nathan Nobbe
On Fri, Nov 5, 2010 at 10:18 AM, Steve Staples sstap...@mnsi.net wrote:

 On Fri, 2010-11-05 at 10:06 -0600, Nathan Nobbe wrote:
  On Fri, Nov 5, 2010 at 9:48 AM, Steve Staples sstap...@mnsi.net wrote:
 
   Hey guys (and gals)
  
   I am writing something that needs to connect to a SMB server... can
 this
   be done easliy?
  
   I copied a sample code from php.net that used the system() command and
   mounted the SMB to a /mnt/tmp partion, and technically, it works
 the
   problem is, is that mount has to be run as root...
  
   is there a way to put the mount/unmount commands into an allowed
   command?   i supposed, the other problem is, is waht if this is on a
   windows machine?
  
   i dont really want to mess with permissions too much, since this will
   have to be portable from linux to windows...   any help would be
   appreciated...
  
 
  is there any reason the php application code has to be responsible for
  mounting the network drive?
 
  typically this is an os-level responsibility.
 
  -nathan

 this is true, but i am looking at mounting it, reading the contents,
 maybe moving a file to it, or renaming a file... and then closing the
 smb share.

 i have thought abotu making it a requirement on the users end to have
 the directory ready for the application... but thought also about maybe
 giving them the option to connect to it and do what it has to do, then
 close it...

 i've been doing it the second way, but was wondering if the first was a
 viable option or not.


hmm, yeah im not sure if theres a clean mounting interface between windows
and linux.  the nomenclature is different for one, and im not even sure how
to mount a network drive programmatically under windows.  maybe someone else
on the list does.

-nathan


Re: [PHP] Re: read smb drive

2010-11-05 Thread Nathan Nobbe
On Fri, Nov 5, 2010 at 10:37 AM, Ian php_l...@fishnet.co.uk wrote:

 On 05/11/2010 16:18, Steve Staples wrote:
  On Fri, 2010-11-05 at 10:06 -0600, Nathan Nobbe wrote:
  On Fri, Nov 5, 2010 at 9:48 AM, Steve Staples sstap...@mnsi.net
 wrote:
 
  Hey guys (and gals)
 
  I am writing something that needs to connect to a SMB server... can
 this
  be done easliy?
 
  I copied a sample code from php.net that used the system() command and
  mounted the SMB to a /mnt/tmp partion, and technically, it works
 the
  problem is, is that mount has to be run as root...
 
  is there a way to put the mount/unmount commands into an allowed
  command?   i supposed, the other problem is, is waht if this is on a
  windows machine?
 
  i dont really want to mess with permissions too much, since this will
  have to be portable from linux to windows...   any help would be
  appreciated...
 
 
  is there any reason the php application code has to be responsible for
  mounting the network drive?
 
  typically this is an os-level responsibility.
 
  -nathan
 
  this is true, but i am looking at mounting it, reading the contents,
  maybe moving a file to it, or renaming a file... and then closing the
  smb share.
 
  i have thought abotu making it a requirement on the users end to have
  the directory ready for the application... but thought also about maybe
  giving them the option to connect to it and do what it has to do, then
  close it...
 
  i've been doing it the second way, but was wondering if the first was a
  viable option or not.
 
  Steve
 
 
 Hi,

 To do this without giving your web site root permissions you will have
 to split out the required actions.


not true, this could easily be facilitated through sudo on linux, which
would eliminate the need for an extra moving part like a running daemon.  in
fact that would be the first solution i would propose on a linux system.

again tho, on the windows side, who knows, lol.

-nathan


Re: [PHP] read smb drive

2010-11-05 Thread Nathan Nobbe
On Fri, Nov 5, 2010 at 10:43 AM, Richard Quadling rquadl...@gmail.comwrote:

 On 5 November 2010 16:30, Nathan Nobbe quickshif...@gmail.com wrote:
  On Fri, Nov 5, 2010 at 10:18 AM, Steve Staples sstap...@mnsi.net
 wrote:
 
  On Fri, 2010-11-05 at 10:06 -0600, Nathan Nobbe wrote:
   On Fri, Nov 5, 2010 at 9:48 AM, Steve Staples sstap...@mnsi.net
 wrote:
  
Hey guys (and gals)
   
I am writing something that needs to connect to a SMB server... can
  this
be done easliy?
   
I copied a sample code from php.net that used the system() command
 and
mounted the SMB to a /mnt/tmp partion, and technically, it works
  the
problem is, is that mount has to be run as root...
   
is there a way to put the mount/unmount commands into an allowed
command?   i supposed, the other problem is, is waht if this is on a
windows machine?
   
i dont really want to mess with permissions too much, since this
 will
have to be portable from linux to windows...   any help would be
appreciated...
   
  
   is there any reason the php application code has to be responsible for
   mounting the network drive?
  
   typically this is an os-level responsibility.
  
   -nathan
 
  this is true, but i am looking at mounting it, reading the contents,
  maybe moving a file to it, or renaming a file... and then closing the
  smb share.
 
  i have thought abotu making it a requirement on the users end to have
  the directory ready for the application... but thought also about maybe
  giving them the option to connect to it and do what it has to do, then
  close it...
 
  i've been doing it the second way, but was wondering if the first was a
  viable option or not.
 
 
  hmm, yeah im not sure if theres a clean mounting interface between
 windows
  and linux.  the nomenclature is different for one, and im not even sure
 how
  to mount a network drive programmatically under windows.  maybe someone
 else
  on the list does.
 
  -nathan
 

 You don't need to mount the share. If the share is available, then
 you can access using UNC ...

 But you don't need to mount the share

 Is this not the same on unix?


im not sure, ive got some linux machines mounting windows shares and it
seems ls is not happy using the smb url to the share.  there may be a way
though, for those willing to dig a little :D

-nathan


Re: [PHP] read smb drive

2010-11-05 Thread Nathan Nobbe
On Fri, Nov 5, 2010 at 11:01 AM, Alexandr verbitsky_alexa...@mail.bywrote:

 Nathan Nobbe пишет:

  On Fri, Nov 5, 2010 at 10:43 AM, Richard Quadling rquadl...@gmail.com
 wrote:



 On 5 November 2010 16:30, Nathan Nobbe quickshif...@gmail.com wrote:


 On Fri, Nov 5, 2010 at 10:18 AM, Steve Staples sstap...@mnsi.net


 wrote:


 On Fri, 2010-11-05 at 10:06 -0600, Nathan Nobbe wrote:


 On Fri, Nov 5, 2010 at 9:48 AM, Steve Staples sstap...@mnsi.net


 wrote:


 Hey guys (and gals)

 I am writing something that needs to connect to a SMB server... can


 this


 be done easliy?

 I copied a sample code from php.net that used the system() command


 and


 mounted the SMB to a /mnt/tmp partion, and technically, it works


 the


 problem is, is that mount has to be run as root...

 is there a way to put the mount/unmount commands into an allowed
 command?   i supposed, the other problem is, is waht if this is on a
 windows machine?

 i dont really want to mess with permissions too much, since this


 will


 have to be portable from linux to windows...   any help would be
 appreciated...



 is there any reason the php application code has to be responsible for
 mounting the network drive?

 typically this is an os-level responsibility.

 -nathan


 this is true, but i am looking at mounting it, reading the contents,
 maybe moving a file to it, or renaming a file... and then closing the
 smb share.

 i have thought abotu making it a requirement on the users end to have
 the directory ready for the application... but thought also about maybe
 giving them the option to connect to it and do what it has to do, then
 close it...

 i've been doing it the second way, but was wondering if the first was a
 viable option or not.


 hmm, yeah im not sure if theres a clean mounting interface between


 windows


 and linux.  the nomenclature is different for one, and im not even sure


 how


 to mount a network drive programmatically under windows.  maybe someone


 else


 on the list does.

 -nathan



 You don't need to mount the share. If the share is available, then
 you can access using UNC ...

 But you don't need to mount the share

 Is this not the same on unix?




 im not sure, ive got some linux machines mounting windows shares and it
 seems ls is not happy using the smb url to the share.  there may be a way
 though, for those willing to dig a little :D

 -nathan



 You can use 'smbclient' for copy file from the machine running the
 client (Linux) to the server (Windows). In PHP it is necessary to use
 functions like system or shell_exec.


ahh - good call.  iirc that's the underlying program used by mount actually
when mounting smb shares.  i know it's called by our automount scripts as
well.  never bothered to use it directly, however that sounds like the way
to go in this scenario.

-nathan


Re: [PHP] Shopping cart question

2010-11-05 Thread Nathan Nobbe
On Fri, Nov 5, 2010 at 12:30 PM, Jack jacklistm...@gmail.com wrote:

 Hello All,


 I'm looking to build a DB with items that are considered more of a catalog
 on one side of a website, and then provide those same items including the
 same images, descriptions etc. to a shopping cart.

 I don't want to re-invent all of the basic shopping cart functionality and
 I'm not sure I want to use something like OScommerce and inject the data
 into it at the same time as putting data into our database that we are
 writing.


 I was hoping someone out there has some suggestions, or even a cart module
 that would allow me to easily integrate into.


One recommendation I can give you is to spend some time determining if
Magento works for you.  This is a conventional platform written on top of
Zend Framework.  OScommerce, and a derivative, ZenCart are ancient, and
there are many nasty things about the programming practices, most notably,
the 'view' layer, which is markup intermingled with logic .. its pretty bad.

Magento is robust, and has a feature set that makes OScommerce look like it
shipped from the third world.  That said it may be overkill as well - just
my 2c.

-nathan


Re: [PHP] PHP sockets enabled but socket_create() gives an error call to undefined function

2010-11-04 Thread Nathan Nobbe
On Thu, Nov 4, 2010 at 11:11 AM, Suyash R r.suy...@gmail.com wrote:

 On Tue, Nov 2, 2010 at 5:49 PM, Nathan Nobbe quickshif...@gmail.comwrote:

 On Tue, Nov 2, 2010 at 2:33 PM, Suyash R r.suy...@gmail.com wrote:

 No, we didn't try it our dept.'s admin wants to know where is sockets.so
 file on disk


 lol, tell your dept.'s 'admin' to run

 locate sockets.so


 yeah he couldn't find it either. He mentioned it's not in the php
 extensions so I am looking for way to install it or add it.


you may need to update the locate database.  this is typically done w/ the
updatedb command.


  and why should we try this when the phpinfo() displays sockets being
 enabled?


 probly there is no need to, however you should understand the difference
 between adding support for and enabling an extension.

 compiling w/ --enable only makes the extension available.  the extension
 is not enabled unless you do what Nick has been saying.  (there are other
 options as well actually).  there may be other files aside from php.ini
 where this setting is made, depending on how the OS vendors package up the
 code.  for example using mac ports, i just installed sockets and now have a
 shiny new sockets.ini file.

 anyway if phpinfo() shows that sockets are enabled you probly don't have
 to worry about that, because it wouldn't be showing up otherwise
 (essentially).

 i'm wondering if you're trying to call socket_create() from the same place
 you're running phpinfo().  are you sure the socket_create() code isn't
 running from the cli perhaps?


 yes to see the errors we ran it at cli. The browser page with sockets code
 is just blank.


right, well if your report from the other day is accurate then it sounds
like you have sockets setup in the web environment and not the cli.  if the
browser page is blank it could be b/c your not outputting anything from your
script to the browser.


 if so, a quick test to see if sockets are enabled on the cli is

 php -i | grep 'Sockets Support'


 Yeah, this gives no results. Hence, I think sockets are not enabled yet as
 sockets.so is missing.


run updatedb first before running locate and see if it's there or not.  im
not sure how phpinfo() could possibly have reported sockets as being enabled
if you were missing sockets.so.


 if nothing comes back sockets aren't enabled for the cli.  if that's the
 case then you will have to head into the appropriate ini file to enable the
 extension for the cli.  or if that's too much for you admin you can always
 try

 dl('sockets.so');

 at the top of your script.  you can also try

 var_dump(extension_loaded('sockets'));


 When I add this line (dl('sockets.so');) to the top of my script I get the
 following error:


 PHP Warning:  dl(): Unable to load dynamic library './sockets.so' -
 ld.so.1: php: fatal: ./sockets.so: open failed: No such file or directory in
 //r.php on line 2
 PHP Fatal error:  Call to undefined function socket_create() in
 /.r.php on line 24

 When I add this line (var_dump(extension_loaded('sockets'));) to the top of
 my script:
 bool(false)
 PHP Fatal error:  Call to undefined function socket_create() in
 /../r.php on line 24


so it's def not enabled on the cli.


 to see if sockets are actually enabled where you're trying to invoke them
 from.

 -nathan

 Can I get any help on how to add or install sockets.so to the php
 extensions...


im not much for red hat, do they even use yum on that system or is it still
rpm?  on a centos box we have a quick search turns up a sockets package,
however if you built from source, i doubt that's how you want to install
sockets support at this point.

$ yum search php | grep -i socket
php-pear-Net-Socket.noarch : Network Socket Interface

also dude, it sounds like your admin is struggling...  these questions are
the sort an admin would be expected to answer pretty much anywhere ive ever
worked.  like, how do i install software on the os im responsible for ..
OUCH!

-nathan


Re: [PHP] PHP sockets enabled but socket_create() gives an error call to undefined function

2010-11-04 Thread Nathan Nobbe
On Thu, Nov 4, 2010 at 11:43 AM, Nathan Nobbe quickshif...@gmail.comwrote:

 $ yum search php | grep -i socket
 php-pear-Net-Socket.noarch : Network Socket Interface


check that - thats def *not* the package you're looking for, it's a
userspace oo wrapper.  you'd be best asking how to install this software on
some sort of red hat / php list really.  like i said, i tend to stay away
from red hat.

the gentoo guys have #gentoo-php on irc so i would expect there to be
similar channels for other distros.

still though, update the locate database and see if you just need to enable
sockets in a cli specific ini file.

-nathan


Re: [PHP] time zone ignored (both via ini or in code)

2010-11-02 Thread Nathan Nobbe
On Tue, Nov 2, 2010 at 7:52 AM, Dan Yost yod...@gmail.com wrote:


 So now I suppose the thread becomes: how do I get a valid US/Central
 (America/Chicago) timezone in PHP5?


give the timezonedb extension a shot

http://pecl.php.net/package/timezonedb

-nathan


Re: [PHP] time zone ignored (both via ini or in code)

2010-11-02 Thread Nathan Nobbe
On Tue, Nov 2, 2010 at 8:44 AM, Dan Yost yod...@gmail.com wrote:

 On Tue, Nov 2, 2010 at 9:19 AM, Nathan Nobbe quickshif...@gmail.com
 wrote:
  On Tue, Nov 2, 2010 at 7:52 AM, Dan Yost yod...@gmail.com wrote:
 
  So now I suppose the thread becomes: how do I get a valid US/Central
  (America/Chicago) timezone in PHP5?
 
  give the timezonedb extension a shot
  http://pecl.php.net/package/timezonedb


 Tried it, no change. It is still impossible to get simple CENTRAL
 timezone output. This is maddening.


That's really weird since I'm sure php has its own timezone db, and it
sounds like that's where PHP is getting it if you saw the correct output
after switching date.timezone to America/Denver.  What about trying
date_default_timezone_set() ?

-nathan


Re: [PHP] time zone ignored (both via ini or in code)

2010-11-02 Thread Nathan Nobbe
On Tue, Nov 2, 2010 at 10:11 AM, Dan Yost yod...@gmail.com wrote:

 On Tue, Nov 2, 2010 at 11:02 AM, Nathan Nobbe quickshif...@gmail.com
 wrote:
  
   So now I suppose the thread becomes: how do I get a valid US/Central
   (America/Chicago) timezone in PHP5?
  
   give the timezonedb extension a shot
   http://pecl.php.net/package/timezonedb
 
 
  Tried it, no change. It is still impossible to get simple CENTRAL
  timezone output. This is maddening.
 
  That's really weird since I'm sure php has its own timezone db, and it
  sounds like that's where PHP is getting it if you saw the correct output
  after switching date.timezone to America/Denver.  What about trying
  date_default_timezone_set() ?


 I had tried that originally too. It does set the timezone correctly,
 but then again so does the ini set. So the timezone does get set to
 America/Chicago with a date_default_timezone_set(), and then PHP
 shanks from there, showing UTC. It seems certain that the timezone
 *does* get set to America/Chicago (via multiple methods), and that
 America/Chicago *itself* is corrupt in PHP--and that's even with
 timezonedb installed. Now everybody knows Chicago is full of
 corruption, but at least the clocks aren't, right?

 Surely there are bizillions of others out there running this
 combination of software in the Central time zone! Yet it's as if
 nobody else has corrupt timezone DB records (be they internal or via
 timezonedb) except me. And I can't help but notice how CentOS (tzdata
 package) is also corrupt, every single time it gets updated, on the
 Central zone but no others. Obviously these should be entirely
 separate issues, but somebody out there has it out for the Central
 time zone. Probably a Yankees fan.


dude at this point i dont want to sound too much like a troll, but php 5.1
is some really old software.  frankly this is why i chose not to run on
centos during my evaluation of it.  i understand the concept behind running
proven stable software, but i think centos is taking that notion to the
extreme.  i would probly try building a more recent version of php from
source and see if that helps.

-nathan


Re: [PHP] time zone ignored (both via ini or in code)

2010-11-02 Thread Nathan Nobbe
On Tue, Nov 2, 2010 at 10:37 AM, Nathan Nobbe quickshif...@gmail.comwrote:

 dude at this point i dont want to sound too much like a troll, but php 5.1
 is some really old software.  frankly this is why i chose not to run on
 centos during my evaluation of it.  i understand the concept behind running
 proven stable software, but i think centos is taking that notion to the
 extreme.  i would probly try building a more recent version of php from
 source and see if that helps.


yeah, we have one centos box left on our network atm, 5.2

$ cat /etc/redhat-release
CentOS release 5.2 (Final)

php 5.2.6

$ php -v
PHP 5.2.6 (cli) (built: May  5 2008 14:41:03)
Copyright (c) 1997-2008 The PHP Group

looks like if i set the timezone explicitly the date functions are working
correctly (obviously though im not sure if this is a 5.1 vs 5.2 issue, just
saying :D)

php  echo Br . strftime(%D %T %z %Z) . br;
Br11/02/10 10:40:12 -0600 MDTbr

php  date_default_timezone_set('America/Chicago');
php  echo Br . strftime(%D %T %z %Z) . br;
Br11/02/10 11:40:53 -0500 CDTbr

-nathan


Re: [PHP] Implementing optional methods in a concrete class, but calling them from an abstract class.

2010-11-01 Thread Nathan Nobbe
On Mon, Nov 1, 2010 at 9:13 AM, Richard Quadling rquadl...@gmail.comwrote:

 Hi.

 I have an abstract base class (call it genericServiceHandler).

 I have concrete classes (FaxService, EmailService).

 The genericServiceHandler is watching for commands from an external
 source. The commands will always be one of a fixed set, no matter what
 the concrete service is. They are Pause, Continue, Start, Stop,
 Shutdown, PreShutdown.

 The genericServiceHandler has no need to process the commands. It only
 receives them and maybe dispatches them to the concrete class.

 The concrete class doesn't have to implement handlers for all of the
 commands, though, at a minimum, onStart() would be pretty much
 essential.


 My question relates to how should I code this.

 Should the base class have empty protected stubs to allowing the
 concrete class to override them via inheritance?

 Should I use __call() to capture the non-existing methods and use LSB
 to allow the concrete class to get the commands?


 I need to document this (phpdoc) to allow those designing the actual
 services know what to implement.

 The empty stubs certainly seems the easiest as I can block the scope
 to protected and include a full reasoning on when the method will be
 called (not all commands are applicable at all times).

 Using __call() can be documented using @method, but pretty much only a
 single line of description.



 What would you all do?


i would go w/ the stubbed out methods in the base class. if theres nothing
to do for the default implementation just use the 'null' pattern,

function pause() {}

 __call is something of a last resort for me; i think it's best for proxies
or similar and thats about the most its useful for.

-nathan


Re: [PHP] include html

2010-11-01 Thread Nathan Nobbe
On Sunday, October 31, 2010, a...@ashleysheridan.co.uk
a...@ashleysheridan.co.uk wrote:
 This can only be done with javascript, as the iframe is client-side, which 
 php knows nothing about.

 sounds to me like OP is building the page which will have the iframe
in it which means this is totally doable server side.  in fact, id
almost prefer server side as that allows masking of the origin making
overriding css values easier afaict.

 I am building a website for a tshirt company that uses another
 company to get garments and promo items to print on.
 The client wants to just have those pages load on top of their
 website, but wants the layout to go with their look and feel. their css.
 We have the go ahead from the other companies to do so as well.

Karl,

this could be done server or client side, however the trouble is
altering the css for every page inside the iframe could be a real
pain.  basically what you could do is act as a proxy, each 'page' from
the original site should be 'made a page' on your site.  basically
youll have to change anchor tag href attributes so each request that
would go back to the original site goes through your site first.  that
way youll have the chance to change the result before handing it back
to the client.  also youll obviously need to change the url to css
file(s) per your primary requirement.  if you do as i suggested above
and make the remote site appear as being served from your domain, you
should be able to get away w/ using a css file served from your domain
as well.

as one of my college professors used to say however, the devil is in
the details, mwahaha.  i would recommend initially experimening to see
if you can use w/e look  feel customizations the remote site offers
to determine if embedding in the iframe w/o any proxy effort is
possible.

-nathan

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



Re: [PHP] time zone ignored (both via ini or in code)

2010-11-01 Thread Nathan Nobbe
On Mon, Nov 1, 2010 at 12:54 PM, Dan Yost yod...@gmail.com wrote:

 Greetings,

 I've looked through a number of different archived threads (some
 rather heated) and samples as well, but clearly I'm just missing
 something.

 PHP 5.1.6
 CentOS release 5.5 (Final)

 My server is in Central Time (US). We do observe DST. I noticed
 functions like strftime() display UTC time. So I undertook fixing
 this.

 I read several threads about setting date.timezone in php.ini, and
 arguments for/against different timezone methods. But in my case I see
 no reason why setting the timezone in php.ini would hurt us--we can
 live with that. And yet:

 [...@ez2 html 13:47:20]$ date
 Mon Nov  1 13:50:05 CDT 2010

 Good.

 [...@ez2 html 13:50:05]$ grep -i timezone /etc/php.ini
 date.timezone = America/Chicago

 Good--and yes, Apache was restarted. So far, we're Central, life is good.

 Let's hit PHP now:

 
 ?
 if (date_default_timezone_get()) {
echo 'date_default_timezone_get: ' . date_default_timezone_get() . 'br
 /';
 }

 if (ini_get('date.timezone')) {
echo 'date.timezone: ' . ini_get('date.timezone');
 }

 echo Br;

 $localtime = localtime();
 $localtime_assoc = localtime(time(), true);
 print_r($localtime);
 print_r($localtime_assoc);


 echo Br . strftime(%D %T %z %Z) . br;

 ?
 


 Which produces:


 date_default_timezone_get: America/Chicago
 date.timezone: America/Chicago
 Array ( [0] = 14 [1] = 51 [2] = 18 [3] = 1 [4] = 10 [5] = 110
 [6] = 1 [7] = 304 [8] = 0 ) Array ( [tm_sec] = 14 [tm_min] = 51
 [tm_hour] = 18 [tm_mday] = 1 [tm_mon] = 10 [tm_year] = 110
 [tm_wday] = 1 [tm_yday] = 304 [tm_isdst] = 0 )
 11/01/10 18:51:14 + UTC


 Timezone is America/Chicago, yet date functions completely ignore this
 and continue to display UTC.

 Please help me understand where I'm blind here.


a few thoughts,

1. set error_reporting to E_ALL to see if the engine is trying to tell you
something you may be overlooking

2. for grins, maybe see if the TZ environment variable is set on your system
var_dump(getenv('TZ'));

3. another test would be to set date.timezone to something else and see if
date_default_timezone_get() returns that new value, which would indicate
it's falling through to the third option in the precedence chain.

lastly you might see if the calling date_default_timezone_set() does the
trick.

-nathan


Re: [PHP] include html

2010-11-01 Thread Nathan Nobbe
On Mon, Nov 1, 2010 at 11:22 PM, Karl DeSaulniers k...@designdrumm.comwrote:

 I need to basically grab the source of the page as text. Then I can do a
 replace() on the link tag. Then insert the text into an Iframe. In theory,
 this I thought would be handled better server side. Is this possible?


yes, there are a few options, fopen wrappers, curl or raw sockets all come
to mind.  fopen wrappers sound like they may be easiest for you.


 I think the problem I'm having is that the domain I'm requesting from is
 not the same domain as mine so their may be some security issue.


right, this is why you would setup a server side proxy, to avoid client side
cross domain security restrictions, however you'll have to change all the
instances of the remote domain to your domain, and ensure that your server
actually is able to fulfill requests for those resources.


 I also thought about injecting a link tag into the iframe at the same time
 I load the HTML.


when you say link tag are you talking about a tags?  you lost me on this
last line here.


 Browsers load the last style sheet on top of others.


this is true, but i doubt you'll be able to have it load a css file from
your domain atop a css file from a remote domain.


  If I could just get the link tag into the iframes contents right after I
 get the source text in there, it may work. But there is also the issue of
 correctly assigning the classes and I'd that are used in the iframe. Like

 iframe.holder .someclassusedbythem {}

 Or do I do?

 iframe#holder .someclassusedbythem {}

 Or

 #holder .someclassusedbythem {}

 Sorry if I'm OT with that.


shrug, no worries, but im too lazy to dig into the details of client side
options. :)

-nathan


Re: [PHP] PHP with POSIX style message queues (mq_open() and friends)

2010-10-28 Thread Nathan Nobbe
On Thu, Oct 28, 2010 at 12:52 PM, Jameson Williams 
jame...@jamesonwilliams.com wrote:

 Hello,

 I need some way to interact with a POSIX message queue from PHP. I am
 already aware that the PHP library provides for manipulation of Sys V style
 queues (msg_get_queue(), etc.), but I cannot change the queue. I am hoping
 to accomplish this capability in a portable way, avoiding external
 dependencies if possible. So far, these are two solutions I have thought
 of:

 * Build a PHP extension which exposes these functions.
 * Build a set of wrapper binaries that can be called via shell_exec() or
 shell()

 For performance reasons, the second is nearly a non-option. Is, then, the
 first option the only way to go about this?


wouldn't calling the wrapper binaries via exec() be faster w/o the shell
overhead?

-nathan


Re: [PHP] Reminder On Mailing List Rules

2010-10-21 Thread Nathan Nobbe
On Thu, Oct 21, 2010 at 8:47 AM, Daniel Brown danbr...@php.net wrote:

 On Thu, Oct 21, 2010 at 10:41, Robert Cummings rob...@interjinn.com
 wrote:
 
  I can't speak for everyone here (or who is no longer here)... but my
 posts
  have dwindled significantly due to work and family time constraints :|

 Same here, but isn't it a bit eerie that many of us hit that same
 point almost simultaneously?  Richard Lynch, Lester Caine, Jochem
 Maas, Jim Lucas, the Nathans (Rixham and Nobbe), yourself, myself -
 even Tedd Sperling and Jason Pruim, among many others - seemed to all
 fall off the face of the virtual earth at about the same moment.  Then
 again, I suppose that's how generations work.


It might be a bit selfish Dan, and I'll admit that, but when I was posting
aggressively I was looking to really boost my PHP skills.  Frankly I think
this list was a major contributor to rapid success in the industry, and I
always tell fellow developers to join the list if they're looking for a
similar boost.

Just for the record, my #1 favorite thread was the argument about php4 vs 5
oo, when Tony Marsten and I were going at it tooth and nail and Rob showed
how to change the value of a private member variable via serialization -
EPIC!

Dan I also remember when you were sending the tally of weekly posts per
contributor at the end of each week, which I think spurred activity for some
time.

I still hop on threads from time to time, just a lot more picky about which
ones any more. ducks

-nathan


Re: [PHP] Reminder On Mailing List Rules

2010-10-21 Thread Nathan Nobbe
On Thu, Oct 21, 2010 at 1:51 PM, Michael Shadle mike...@gmail.com wrote:

 in fact, it's easier to read on mobile devices such as an iphone. it's
 also easier to reply.

 email clients like google will hide the common lines anyway.

 to me this comes on the heels of a presentation i just read about
 there's no such thing as a 'mobile site' as in - everything on the
 web now is consumed by multiple devices, that should include email as
 well. while ascending discussion makes sense, email clients are smart
 enough to pick things apart for you now...


um, right, the whole point is that the conversations are not being viewed
through mail clients when people are finding them via search engines on the
web.

and some mail clients are dumber than others, lol.

-nathan


Re: [PHP] Reminder On Mailing List Rules

2010-10-21 Thread Nathan Nobbe
On Thu, Oct 21, 2010 at 2:15 PM, Michael Shadle mike...@gmail.com wrote:

 On Thu, Oct 21, 2010 at 12:56 PM, Nathan Nobbe quickshif...@gmail.com
 wrote:

  um, right, the whole point is that the conversations are not being viewed
  through mail clients when people are finding them via search engines on
 the
  web.
  and some mail clients are dumber than others, lol.

 a lot of the time even the web-based list sites now even do syntax
 highlighting and stuff :p


what does syntax highlighting have to do w/ a mess of text that could be
sorted out by folks willing to take the extra 2 seconds to put their
thoughts at the bottom of a mail?

i doubt there are any web-based lists that reorganize top-posted replies,
but if you find one, id love to see it :P

-nathan


Re: [PHP] Reminder On Mailing List Rules

2010-10-21 Thread Nathan Nobbe
On Thu, Oct 21, 2010 at 2:33 PM, Michael Shadle mike...@gmail.com wrote:

 On Thu, Oct 21, 2010 at 1:21 PM, Nathan Nobbe quickshif...@gmail.com
 wrote:

  what does syntax highlighting have to do w/ a mess of text that could be
  sorted out by folks willing to take the extra 2 seconds to put their
  thoughts at the bottom of a mail?
  i doubt there are any web-based lists that reorganize top-posted replies,
  but if you find one, id love to see it :P

 because it de-dupes or changes colors for the previous replies.


shrug, it still doesnt organize the responses into the cohesive manor
correlating specific responses to specific portions of the previous message.
 ive found this technology to be fickle as it's based on  characters being
embedded into responses, which of course are not properly done when
top-posting.


 and again - it doesn't take 2 seconds to clean up an email and throw a
 reply at the bottom on something like an iphone. that can take a
 while.


just like dan, i have chosen to refrain from posting until a later time,
like when i get home, or for someone else to invariably post next to the
same thing i would have in the absence of said post.  if i have something
monumental to say that no one else does, i have the patience to wait that 30
minutes or w/e to get home and post it.


 at the end of the day, i don't give a crap how people post. i am able to
 read anyone's messages just fine.


you clearly are a very gifted individual Michael.


 i don't know why anyone is complaining in the modern age.


see the previous posts in this thread.

i've found top-posting to be useful in the corporate environment where the
people i'm working with are too ignorant to understand the rationale.
 however, when you're working with programmers, i think the expectation is
more than reasonable as well the rationale behind it being understood.
 top-posting is also useful for trivial communications where only 1 or 2
replies will ever be sent.  however, in long running complicated threads it
quickly results in replies that are difficult to follow, specifically b/c it
becomes non-trivial to correlate which portion of the previous message the
author was addressing; at the very least, it introduces ambiguity.

and more to the topic of this thread, the degradation of the communication
here is a great example of another reason i've stopped being so active.
 there are standards established by the list, if you can't follow them,
maybe you belong on the sidelines as an observer.

-nathan


Re: [PHP] Reminder On Mailing List Rules

2010-10-21 Thread Nathan Nobbe
On Thu, Oct 21, 2010 at 4:24 PM, Michael Shadle mike...@gmail.com wrote:

 On Thu, Oct 21, 2010 at 3:12 PM, Nathan Nobbe quickshif...@gmail.com
 wrote:

  i've found top-posting to be useful in the corporate environment where
 the
  people i'm working with are too ignorant to understand the rationale.
   however, when you're working with programmers, i think the expectation
 is
  more than reasonable as well the rationale behind it being understood.
   top-posting is also useful for trivial communications where only 1 or 2
  replies will ever be sent.  however, in long running complicated threads
 it
  quickly results in replies that are difficult to follow, specifically b/c
 it
  becomes non-trivial to correlate which portion of the previous message
 the
  author was addressing; at the very least, it introduces ambiguity.
  and more to the topic of this thread, the degradation of the
 communication
  here is a great example of another reason i've stopped being so active.

 i agree, truly discussing something that is against your opinion
 should definitely be considered degradation

   there are standards established by the list, if you can't follow them,
  maybe you belong on the sidelines as an observer.

 yes, certainly people who do not have the patience to wait until
 they're home on a more formal PC in an increasing age of mobile do not
 belong in any discussions online. so while that audience is growing,
 their influence should be reduced. great math there.


its not my fault the mobile browsers aren't as capable as the ones on pc's.
 i've been on a decent mobile device since the iphone 3g.  i do like your
logic of the larger audience being the one calling the shots in the online
experience, however, while mobile is quickly outpacing the pc, i'm sure the
pc environment is still the larger of the two atm.

furthermore, i find this usage of the term standards is quite
 amusing. assigning a standard to a freeform discussion capability
 should be a farce, especially when you can't even consider web
 development RFCs standards when different browsers implement them
 different ways.


lol, poignant, an amusing question is how many standards does it take
before it's no longer a standard.  well call it etiquette then, it's like
joining a club and finding out they don't want guys pissing on the floors in
the public showers.


 perhaps you should just unsubscribe then, if this list is introducing
 so much more effort into your day to read.


shrug, since i still use php a good deal in my daily life, i choose to
ignore most of the topics as they are repeats many times anyways.  typically
the people who need to be asked to not top-post are involved in threads that
don't peak my interest.


 note, that i take the time to bottom-post and clean up emails when i
 have time, but if i don't, i don't.


as do i, but i'll be nice enough to excuse myself when breaking protocol.


 people discuss things for discussion, they don't discuss things because
 they care how it is
 placed. that's like getting a present and whining about the wrapping paper.


lol, nice analogy.  i find it more along the lines of if you can't speak the
language the way others are speaking it, they simply can't understand you or
won't bother trying in the first place.  its like classifying ebonics as
english.

-nathan


  1   2   3   4   5   6   7   8   9   10   >