[PHP] Re: $$var

2011-03-07 Thread Colin Guthrie
'Twas brillig, and sexyprout at 06/03/11 15:16 did gyre and gimble:
> ∞

And beyond!


-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mageia Contributor [http://www.mageia.org/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Quotes in Heredoc

2011-02-28 Thread Colin Guthrie
'Twas brillig, and Bob McConnell at 28/02/11 13:23 did gyre and gimble:
> XHTML also requires all tags, attribute labels and values to be in lower
> case and values must be quoted. So your original content should be
> 
>width="621">
>  
>src="../images/spacer.gif">
> 

Actually, in xhtml the  tag would need a corresponding  tag,
or it can be self closing:

e.g. 

(technically the space before the /> bit above is not needed, but used
to be needed to stop older versions of IE from exploding... these
probably are not worth worrying about these days tho')

Col


-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mageia Contributor [http://www.mageia.org/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: "public static" or "static public"?

2011-01-29 Thread Colin Guthrie
'Twas brillig, and David Harkness at 28/01/11 18:41 did gyre and gimble:
> On Fri, Jan 28, 2011 at 10:35 AM, Mujtaba Arshad wrote:
> 
>> Having learned java before even knowing what php was (yeah I'm a noob in
>> both) I prefer scope static function.
> 
> 
> I learned Java first, too, and also prefer the scope first. I place a scope
> on every method, so I'd rather the first word always be the scope rather
> than sometimes scope, sometimes static. I also think of it as a "static
> function" that happens to be "public." Finally, I prefer to group static
> members at the top of the class to differentiate them as a separate API for
> the class itself.

Well that wasn't even vaguely controversial! Was hoping that some people
would have some more "creative" reasoning for both sides!

Ahh well, this all ties in with my view, so I'm not really complaining :D

Cheers for the insights.

Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mageia Contributor [http://www.mageia.org/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] "public static" or "static public"?

2011-01-28 Thread Colin Guthrie
OK, so it's a Friday hence a random debate


What is preferred for class methods?

class foo
{
 static public function bar(){}

 public static function wibble(){}
}

??

All methods are valid, but are some more valid than others? :p

Checking ZF:

[colin@jimmy Zend (working)]$ cgrep "public static function" . |wc -l
755
[colin@jimmy Zend (working)]$ cgrep "static public function" . |wc -l
60

It's clear which is preferred there, but still not absolutely consistent
(I didn't bother checking differently scoped methods).


I personally prefer scope first then "static", but others may have valid
reasons/arguments for preferring the other way.

WDYT?

Col



-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mageia Contributor [http://www.mageia.org/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Flexible application plugin architecture, is this possible?

2011-01-04 Thread Colin Guthrie
'Twas brillig, and Mike at 03/01/11 23:37 did gyre and gimble:
> I'm trying to design a powerful plugin system that doesn't require any
> (or extremely little) modification to my existing large code base. Hook
> based systems unfortunately don't seem to meet this requirement. 
> 
> Is something like this possible in PHP?
> 
> //Magic function I made up, similar to __call(), 
> //only it replaces "new $class" with its own return value.
> function __instantiate( $class, $args ) {
> $plugin_class = $class.'Plugin';
> 
> if ( file_exists( 'plugins/'.$plugin_class.'.php' ) {
> $obj = new $plugin_class($args);
> return $obj;
> } else {
> return new $class($args);
> }
> }

I'd implement the above as a static "factory" method of your primary
class: e.g.

> class MainClass {

public static function factory($args = null) {
$plugin_class = __CLASS__ . 'Plugin';
// Assume autoloading
if (class_exists($plugin_class))
  return new $plugin_class($args);
return new self($args);
}

protected function __construct($args) {
}

> function doSomething( $args ) {
> echo "MainClass doSomething() called...\n";
> }
> }
> 
> class MainClassPlugin extends MainClass {
> function doSomething( $args ) {
> echo "MainClassPlugin doSomething() called...\n";
> 
> //Modify arguments if necessary
> echo "MainClassPlugin modifying arguments...\n";
> 
> $retval = parent::doSomething( $args );
> 
> //Modify function output, or anything else required
> echo "MainClassPlugin post filter...\n";
> 
> return $retval;
> }
> }
> 
> $main_class = new MainClass();

And replace this line with:
$main_class = MainClass::factory();


> $main_class->doSomething( 'foo' );

Which, when run, does indeed produce your desired results.

> Results:
> MainClassPlugin doSomething() called...
> MainClassPlugin modifying arguments...
> MainClass doSomething() called...
> MainClassPlugin post filter...
> 
> I realize PHP doesn't have this magical "__instantiate" function, but
> does it have any similar mechanism that would work to automatically
> load alternate classes, or have a class dynamically overload
> itself during runtime?

Well difference techniques require different approaches, but certainly a
factory approach is likely the correct design solution here to get the
desired results.


Full code for convenience:

doSomething( 'foo' );


-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mageia Contributor [http://www.mageia.org/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Under which distribution(s) is PHP developed, compiled, and tested?

2010-12-15 Thread Colin Guthrie
'Twas brillig, and Dan Schaefer at 15/12/10 14:28 did gyre and gimble:
> Background (some of these facts may be well-known, and for that I
> apologize):
> I'm running CentOS 5.5 on all servers, which only supports PHP 5.1.6
> CentOS 5.5 is based off RHEL 5.5
> Redhat has released RHEL 6 which supports PHP 5.3
> CentOS has not released even a beta 6 version yet that supports PHP 5.2+

The *official* RPMs for CentOS 5.5 are PHP 5.1.6 but there are plenty
third party repos where never versions are made available.

e.g. http://iuscommunity.org/getting-started/

HTHs

Col


-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mageia Contributor [http://www.mageia.org/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Apache mod_pagespeed

2010-11-04 Thread Colin Guthrie
'Twas brillig, and Daniel P. Brown at 04/11/10 14:36 did gyre and gimble:
> I'm already highly impressed with mod_pagespeed.  It even
> removes excess spaces - such as those in  tags - without any
> adverse reactions I've seen so far.

Nice. I still stick spaces in my  tags due to the parsing error in
IE(somethingold) but I'm pretty sure that was pre-IE6 and thus something
I really don't care about now!

That said, I'm not sure I'd really want it to optimise all my HTML
pages. CSS, JS and images yes, no problem, but the storage overhead of
the disk cache all the dynamic pages is probably not worth it for me.
But that's presumably just one of the things it can do.

> In any case, there are some minor quirks I've found, so I'm not
> ready to put this into production for any of my client's servers yet,
> but I can see myself starting to do so in two to four weeks, barring
> any horrible discoveries.

The build process looks very ugly And it's strange their build page
seems to suggest GCC 4.2 but CentOS 5.5 only has GCC 4.1 so I'm a bit
puzzled as to why it's one of their recommended systems :s

I'll take the build process for a spin at some point, but they really do
need to make it more streamlined.

Col



-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mageia Contributor [http://www.mageia.org/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Apache mod_pagespeed

2010-11-04 Thread Colin Guthrie
'Twas brillig, and Daniel P. Brown at 03/11/10 19:34 did gyre and gimble:
> On Wed, Nov 3, 2010 at 14:48, Shreyas Agasthya  wrote:
>> Thiago,
>>
>> I would like to join this. Let me know how I can help you with this. Please
>> be explicit with your requests so that we can totally test it  and see if it
>> could pose any risk to acceleration services provided by CDNs.
> 
> I've yet to read the specs behind it (I was out of the office),
> but from the overview I did see, it should not only be of no detriment
> to CDNs.  In fact, Google is working with an existing company,
> Cotendo, to integrate the core into their CDN.
> 

Yeah it seems like a nice idea. Basically we already do a "pre-process
stage where we minify css and js before we deploy the application (dev
versions are nicely verbose so that the "javascript error on line 1"
debugging does not plague us!). We also try to pngcrush pngs and
optimise jpegs etc.

But this module seems to do all that stuff for you on the fly which is
pretty nice. It would save over head in terms of application deployment
processes here and I'd likely be happier using it than doing all this
stuff myself.

That said, it's often nice to think about these things rather and learn
about the consequences than just blunder on and hope for the best. This
module will result in a bit of "dumbing down" of devs, but that's not to
say I'm against it generally.

Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mageia Contributor [http://www.mageia.org/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Looking for an open-source project

2010-10-25 Thread Colin Guthrie
'Twas brillig, and Mert Oztekin at 25/10/10 13:23 did gyre and gimble:
> I am looking for an open-source project to help and make some fun. Anyone has 
> suggestions?

How about helping out Zend Framework, adding useful classes for various
Service integrations etc.?

Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mageia Contributor [http://www.mageia.org/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: daemon

2010-10-07 Thread Colin Guthrie
'Twas brillig, and Nathan Nobbe at 07/10/10 06:46 did gyre and gimble:
> On Wed, Oct 6, 2010 at 11:21 PM, Tommy Pham  wrote:
> 
>> Hi,
>>
>> Does anyone have a script running as daemon on Linux/Unix (variants) as
>> part
>> of your PHP application?  If so, what are you using to schedule the script
>> to run? cron?
>>
> 
> cron is one way to do it for scripts you schedule.  for real daemon
> processes though ive recently deployed a php script on gentoo by leveraging
> the init scripts.  essentially my program runs a while(true) and uses
> pcntl_fork() to create worker children.  the parent process listens for
> signals which are sent by an init script.  theres also a really nice
> start-stop-daemon function in the init script library which backgrounds the
> process for me and creates a pid lockfile.  really slick.
> 
> now i have an interface to my script like
> 
> /etc/init.d/php-service start
> 
> etc.  plus it ties right into the runlevel scripts, i just run
> 
> rc-update add php-service default
> 
> and the script will start when the box hits runlevel 3!

Yeah that's what I do too. Of course systemd will change everything
"initscript" related, but I don't expect it to hit production servers
for a while.

Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mageia Contributor [http://www.mageia.org/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Bitwise NOT operator?

2010-08-25 Thread Colin Guthrie
'Twas brillig, and Andy McKenzie at 24/08/10 21:42 did gyre and gimble:
> Even if I'd thought about it in terms of the architecture, I
> would have assumed that PHP would treat a two-bit number as a two-bit
> number

You two-bit hustler!

In all seriousness tho', where do you ever provide a two bit number?

$n = 2;

The above is a number, it's not implicitly a two bit number...

I mean, if I do:

$n = 2;
$n += 2;

What do I get then? $n == 0? That's what *should* happen if $n was
indeed two bits. It would overflow and wrap around.

Your number in $n is in fact represented by whatever the variable type
is. In this case it's a 32 bit integer number.

Col


-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Dear Lazy Web: Pseudo Randomisation Strategies on Listing Websites

2010-08-20 Thread Colin Guthrie
'Twas brillig, and Andrew Ballard at 20/08/10 15:55 did gyre and gimble:
> On Fri, Aug 20, 2010 at 10:19 AM, Colin Guthrie  wrote:
>> The customer is always right -> in his own mind (even if not in his RIGHT 
>> mind) <- after all!
> 
> Corrected that for you.  ;-)

:D

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Bitwise NOT operator?

2010-08-20 Thread Colin Guthrie
'Twas brillig, and Andy McKenzie at 20/08/10 16:10 did gyre and gimble:
> Hey everyone,
> 
>   I'm really not sure what's going on here:  basically, the bitwise
> NOT operator seems to simply not work.  Here's an example of what I
> see.
> 
> Script
> 
> $ cat bintest2.php
> 
>  
> $bin = 2;
> $notbin = ~$bin;
> 
> echo "Bin: " . decbin($bin) . "  !bin:  " . decbin($notbin) . "\n";
> echo "Bin: $bin  !bin:  $notbin\n";
> 
> 
> ?>
> =
> 
> 
> Output
> 
> $ php bintest2.php
> Bin: 10  !bin:  1101
> Bin: 2  !bin:  -3
> 
> =
> 
> 
> Obviously that's not the expected response.  I expect to get something
> more like this:
> 
> Bin: 10  !bin:  01
> Bin: 2  !bin:  1
> 
> 
> Can anyone shed some light on this for me?  


The output looks correct to me, so I think it's your expectations that
are incorrect.

You are assuming that you are working with a 2-bit number the in actual
fact you are working with a 32-bit number.

If you did

$bin = 2;
$notbin = ~$bin & 3;

Then this should get the results you want. The bitwise & 3 bit
essentially limits things to a 2-bit number. (3 in binary is represented
by 1's for the two LSBs and 0's for all other bits).

FWIW, the fact that ~2 == -3 is due to twos compliment binary notation:
http://en.wikipedia.org/wiki/Twos_Compliment

Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Dear Lazy Web: Pseudo Randomisation Strategies on Listing Websites

2010-08-20 Thread Colin Guthrie
'Twas brillig, and Ashley Sheridan at 20/08/10 15:29 did gyre and gimble:
> If you use a sitemap specific to a search engine (Google sitemap for
> example) then you can specify how often a page changes, or tell it not
> to index at all. This could help a little in preventing getting
> penalised by a search engine for the indexed content never matching what
> a user actually does see. 

Yeah we do that already (partly to reduce being hammered by bots, but
also because there is no point in indexing too oftent!)

> It brings to mind what a lot of companies do to ensure they are popular
> in the phonebook. Ever noticed how there are an unusually high number of
> companies towards the extreme ends of the alphabet. It was a deliberate
> ploy to get as near to the first or last listing in a phonebook, which
> was always done alphabetically (with the exception of paid-for listings
> which were usually as larger adverts alongside the regular listings) So
> you end up with AAA Cars, AA Electricians, ZZ Plumbers, ZYX Mechanics,
> etc.

Yeah this was a problem for us a few years ago and we had to actually
disable users from editing their own "thing" names for some clients.
This allowed our clients to keep a solid control over it and make sure
that the name were relevant and accurate!

Col


-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Dear Lazy Web: Pseudo Randomisation Strategies on Listing Websites

2010-08-20 Thread Colin Guthrie
'Twas brillig, and Andrew Ballard at 20/08/10 15:04 did gyre and gimble:
> On Fri, Aug 20, 2010 at 9:31 AM, Colin Guthrie  wrote:
>> Speaking of SEO, that was one of our concerns about randomising listings
>> too. What impact do you think such randomised listings will have on SEO?
>>
>> Obviously if a term is matched for a listing page that contains a thing
>> and when the user visits that page, the thing itself is not on in the
>> listing, then the user will be disappointed, but will this actually
>> result in SEO penalties?
>>
>> Col
> 
> I'm not sure it would penalize you in the algorithms. I was thinking
> more of the number of times I have followed a promising-looking link
> and found that the site where I was directed was a page of and index
> of article headings or post subjects showing results 1000-1500 out of
> 1+, and the item I was hoping to see is no longer on that page. Is
> it on the next page? No. Next page? No. Oh, forget it - back go
> [search engine].
> 
> In that case, even if the site's page rank doesn't decrease, the
> search results are out-of-sync and thus inaccurate. The site can
> definitely take a hit with regard to end-user perception and can cause
> annoyed users to leave and/or ignore your site, which are more
> important issues than a number from some search engine's algorithm.
> After all, it doesn't matter how many people Google, Bing, Yahoo or
> some other search engine sends your way if those users end up
> frustrated by the experience and don't actually use the site once they
> get there.

Yeah, these are also my concerns with the approach and we've been
careful to point them out to our client. If they know the potential
risks and they still want to go ahead then we've just got to live with
it, even if we don't agree that it's the right solution. The customer is
always right after all!

Cheers for the comments :)

Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Dear Lazy Web: Pseudo Randomisation Strategies on Listing Websites

2010-08-20 Thread Colin Guthrie
'Twas brillig, and Andrew Ballard at 20/08/10 14:24 did gyre and gimble:
> Would it work to return a list of some limited number of randomly
> ordered "featured" listings/items on the page, while leaving the full
> list ordered by whatever natural ordering (by date, order entered,
> alphabetical, etc.)? That gives every owner a chance to appear in a
> prominent spot on the page while solving the issue you cited about
> page breaks (and SEO if that is a concern). You can still use any of
> the suggestions that have been discussed to determine how frequently
> the featured items list is reseeded to help make caching practical.

Yeah we've tried to push this as an option too, but so far our clients
are not biting on this suggestion. They like the idea but in
addition to randomised listings too!

Speaking of SEO, that was one of our concerns about randomising listings
too. What impact do you think such randomised listings will have on SEO?

Obviously if a term is matched for a listing page that contains a thing
and when the user visits that page, the thing itself is not on in the
listing, then the user will be disappointed, but will this actually
result in SEO penalties?

Col




-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Dear Lazy Web: Pseudo Randomisation Strategies on Listing Websites

2010-08-20 Thread Colin Guthrie
Thanks everyone for responses.

'Twas brillig, and Nathan Rixham at 20/08/10 13:17 did gyre and gimble:
> if you use mysql you can seed rand() with a number to get the same
> random results out each time (for that seed number)
> 
>   SELECT * from table ORDER BY RAND(234)
> 
> Then just use limit and offset as normal.

This is a neat trick! Yeah that will avoid the need for the static
lookup table with 32 randomised columns.

Jon's strategy is more or less a simplified version of my 32-column
randomising table (i.e. just have 1 column of random data rather than
32). I would personally prefer to reduce the refresh of this data as I
don't like to annoy people when the change over day happens.

The RAND(seed) approach will probably work well (not sure of performance
verses an indexed table, but I can easily experiment with this).

If I use the numbers 1..32 as my seed, then I still get the same net
result as a 32 column table. If I just change my "seed offset" then I
get the same result as re-generating my random data tables.

>From an operational perspective, RAND(seed) is certainly easier.

I'll certainly look into this. Many thanks.

Col


-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Dear Lazy Web: Pseudo Randomisation Strategies on Listing Websites

2010-08-20 Thread Colin Guthrie
Hi,

OK, this is really just a sounding board for a couple ideas I'm mulling
over regarding a pseudo-randomisation system for some websites I'm
doing. Any thoughts on the subject greatly appreciated!

Back Story:

We have a system that lists things. The things are broken down by
category, but you can still end up at the leaf of the category with a
couple hundred things to list, which is done via a pagination system
(lets say 50 per page).


Now, the people who own the things pay to have their things on the site.
Lets say there are three levels of option for listing: gold, silver,
bronze. The default order is gold things, silver things then bronze
things. Within each level, the things are listed alphabetically (again
this is just the default).


Now if 100 things in one category have a gold level listing, those in
the second half of the alphabet will be on page two by default. They
don't like this and they question why they are paying for gold at all.

My client would like to present things in a more random way to give all
gold level things a chance to be on the first page of results in a
fairer way than just what they happen to be named.

Right that's the back story. It's more complex than that, but the above
is a nice and simple abstraction.


Problems:

There are numerous problems to randomised listings: you can't actually
truly randomise results otherwise pagination breaks. Server-side
caching/denationalisation is affected as there is no longer "one
listing" but "many random listings". Discussing a link with a friend
over IM or email and saying things like "the third one down looks best"
is obviously broken too, but this is something my client accepts and can
live with. Also, if the intention is to reassure the thing owners that
their listing will appear further up the listings at times, the fact
that a simple refresh will not reorder things for a given session will
make that point harder to get across to less web-educated clients
(that's a nice way of saying it!). Caching proxies and other similar
things after the webserver will also come into play.


So to me there are only really two options:

1. Random-per user (or session): Each user session gets some kind of
randomisation key and a fresh set of random numbers is generated for
each thing. They can then be reliably "randomised" for a given user. The
fact that each user has their own unique randomisation is good, but it
doesn't help things like server side full page caching and thus more
"work" needs to be done to support this approach.

2. Random-bank + user/session assignment: So with this approach we have
a simple table of numbers. First column is an id and is sequential form
1 to . This table has lots of columns: say 32. These
columns will store a random number. Once generated, this table acts as
an orderer. It can be joined into our thing lookup query and the results
can be ordered by one of the columns. Which column to use for ordering
is picked by a cookie stored on the users machine. That way the user
will always get the same random result, even if they revisit the site
some time later (users not accepting cookies is not a huge deal, but I
would suggest the "pick a random column" algorithm (used to set the
cookie initially) is actually based on source IP address. That way even
cookieless folks should get a consistent listing unless their change
their IP).



I'm obviously leaning towards the second approach. If I have 32
"pre-randomised" columns, this would get a pretty good end result I
think. If we re-randomise periodically (i.e. once a week or month) then
this can be extended further (or simply more columns can be added).

I think it's the lowest impact but there are sill some concerns:

Server side caching is still problematic. Instead of storing one page
per "result" I now have to store 32. This will lower significantly the
cache hits and perhaps make full result caching somewhat redundant. If
that is the case, then so be it, but load will have to be managed.


So my question for the lazy-web:

Are there any other approaches I've missed? Is there some cunning,
cleverness that eludes me?

Are there any problems with the above approach? Would a caching proxy
ultimately cause problems for some users (i.e. storing a cache for page
1 and page 2 of the same listing but with different randomisations)? And
if so can this be mitigated?

Thanks for reading and any insights you may have!


Col






-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: tutorial failure

2010-08-20 Thread Colin Guthrie
'Twas brillig, and Ashley Sheridan at 19/08/10 23:16 did gyre and gimble:
> I used the GUI: K-Menu->Configure your Computer->Install & Remove
> Software
> 
> Then searched for 'php', and the first package listed was
> apache-mod_php, which I installed along with the other php modules that
> I normally install (like GD, mcrypt, etc). The package manager sorts out
> dependencies very well. I'm not sure if installing over the command line
> with rpmi will deal with dependencies like this, and it certainly won't
> automatically install apache-mod_php if php is installed, as php doesn't
> necessarily *have* to run as a web server module, let alone as an Apache
> one specifically.

Just for reference:

1. The Package Manager GUI will indeed sort it all out for you.

2. The Package Manager GUI is just a frontend for urpmi. All the
dependency tracking etc. is in urpmi. It's very much like Yum, but IMO
is easer to use and better at reporting conflicts and other such things.
But to each his own :)

3. Just install task-lamp. Who cares that you get mysql installed? I
doubt the space overhead is a problem and I'm very much presuming that
this is your development PC. No offence intended (we were all new once)
the fact that you are asking the questions you are means that this
simply *cannot* be a production setup!

If you have any doubt and want to be more specific, just install
task-lamp-php. All of these are listed in the Package Manager GUI. Just
pick "Meta Packages" and then look under System->Servers (or just search
for the name: staring the GUI and typing "lamp" into the search box is
really all that's needed).

4. Yes PHP can be installed as cgi, apache module or command line. There
is no such thing as "installing php" - you install which system you
want: command line (php-cli), apache module (apache-mod_php) or cgi
(php-cgi). I work with LAMP stacks on various flavours servers and I
find the Mandriva one to be very, very well thought out, and very
flexibly mainly due to the excellent work of Oden Ericsson.

Col




-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: tutorial failure

2010-08-19 Thread Colin Guthrie
'Twas brillig, and e-letter at 19/08/10 13:35 did gyre and gimble:
> On 19/08/2010, David McGlone  wrote:
> 
>> Yes it is. But your computer needs the correct software to view that php
>> file in a web browser as if it was a web page. If you do not have this
>> software installed, then the web browser will ask you if you want to
>> download the file instead.
>>
> The web browser views the php file as described previously; there is
> no prompt to download the file.
> 

You are apparently using Mandriva as you mentioned urpmi in your
original email.

I strongly suggest you do: "urpmi task-lamp" as this will install all
the revenant packages.

I strongly suspect you have not installed the apache-mod_php package.


I should stress that you should *not* have to edit *any* files to get
your system up and running. If you do edit files (especially your apache
configuration) then you really do need to sit down and learn how
everything works and how things fit together.

As you're presumably just starting out, I'd recommend sticking to the
basics, install task-lamp and then go from there.


HTHs

Col




-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Including files on NFS mount slow with APC enabled

2010-08-17 Thread Colin Guthrie
'Twas brillig, and Mark Hunting at 17/08/10 09:08 did gyre and gimble:
> I now notice that when I replace include_once with include the open()
> call disappears. That's very nice, but why does include_once need to
> open the file, even when apc.include_once_override is enabled? Is this a
> bug?

I don't know the internals of APC but that smells like a bug to me.

Can you post the bug number here if you report one?

Cheers

Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]

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



[PHP] Re: PHP images server

2010-08-05 Thread Colin Guthrie
'Twas brillig, and Jean-Michel Philippon-Nadeau at 04/08/10 16:48 did
gyre and gimble:
> Hi List,
> 
> My website uses a lot of external images coming from many different
> websites. Those images are sometimes small, sometimes big, and to
> reduce the loading time of my pages and for better uniformity, I've
> built a small PHP images server that resizes to a predefined set of
> dimensions the images if necessary. To save on CPU usage, the resized
> version is stored on Amazon AWS.
> 
> When requesting an image of a specific size, if the resized image
> exists on AWS, that image is used. The images server then redirects
> the browser to the AWS URL.
> 
> I don't believe having 80 redirections is a very clean solution so, my
> question is: How can I optimize my process while keeping the load on
> Amazon's servers?


Presumably you generate the links to the files to put into HTML or CSS
at some point?

Rather than check if an appropriate sized image is available then the
image is requested, why not check when you generate the link to the the
image? If when you generate the link it is NOT available, do the
necessary stuff to generate it and upload to AWS, then carry on.

Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: php array in different OS

2010-07-23 Thread Colin Guthrie

'Twas brillig, and fyang at 22/07/10 03:34 did gyre and gimble:

Dear Bob McConnell,
Thank you for your reply.
I really post the same message eight times because of the first e-mail 
authentication.please remove the extra e-mail in your free time.
There are two servers ,the first installation of 32-bit linux(RHEL),the 
second installlation 64-bit linux(CENTOS).
PHP version on 32-bit linux(RHEL):5.2.7
PHP version on 64-bit linux(CENTOS):5.2.13
   I found this problem,because the software transplantation.In the 64-bit 
systems,the array seems to always have limited capacity. I'm not sure that is 
php version problem or need other configurations.


I suspect it's just different configuration.

That said, I've generally found that 64bit versions of PHP need more 
memory than their 32bit equivs, so perhaps all you need to do is 
something like:


ini_set('memory_limit', '50M');

and you'll be fine.

Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Logical reason for strtotime('east') and strtotime('west') returning valid results?

2010-04-06 Thread Colin Guthrie
'Twas brillig, and Kevin Kinsey at 05/04/10 19:15 did gyre and gimble:
> Nonetheless, I'm suspecting the programmers had something
> like this in mind. 

Yeah I guess that's why it interprets these terms. Good thinking :)

> Isn't strtotime() based on some GNU utility?

Yeah, that's why I said "the relevant authorities". I couldn't remember
off-hand where it came from so figured I'd not blame "PHP" just yet :p

Cheers

Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Logical reason for strtotime('east') and strtotime('west') returning valid results?

2010-04-05 Thread Colin Guthrie
Hi,

Long time no speak!


As part of a quick filter I'm writing I try to interpret free text
strings as dates and textual data.

Sometimes, this goes wrong.

For example, I discovered that some words (or strings beginning with
those words) will return false positives:

e.g.:

[co...@jimmy Search (working)]$ php -r 'var_dump(strtotime("east"));'
int(1270514111)
[co...@jimmy Search (working)]$ php -r 'var_dump(strtotime("west"));'
int(1270488914)
[co...@jimmy Search (working)]$ php -r 'var_dump(strtotime("now"));'
int(1270488928)


The last one is valid! But the other two appear to do much the same thing...

Can anyone think of why this would be valid results before I report this
to the relevant authorities?

Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: I need a fresh look at storing variables in MySQL

2010-03-15 Thread Colin Guthrie
'Twas brillig, and Jochem Maas at 14/03/10 23:56 did gyre and gimble:
> Op 3/14/10 11:45 AM, Ashley Sheridan schreef:
>> On Sun, 2010-03-14 at 12:25 +0100, Rene Veerman wrote:
>>
>>> On Sun, Mar 14, 2010 at 12:24 PM, Rene Veerman  wrote:
>>>>
>>>> I'd love to have a copy of whatever function you use to filter out bad
>>>> HTML/js/flash for use cases where users are allowed to enter html.
>>>> I'm aware of strip_tags() "allowed tags" param, but haven't got a good list
>>>> for it.
>>>>
>>>
>>> oh, and even  tags can be used for cookie-stuffing on many browsers..
>>>
>>
>>
>> Yes, and you call strip_tags() before the data goes to the browser for
>> display, not before it gets inserted into the database. Essentially, you
>> need to keep as much original information as possible.
> 
> I disagree with both you. I'm like that :)
> 
> let's assume we're not talking about data that is allowed to contain HTML,
> in such cases I would do a strip_tags() on the incoming data then compare
> the output ofstrip_tags() to the original input ... if they don't match then
> I would log the problem and refuse to input the data at all.
> 
> using strip_tags() on a piece of data everytime you output it if you know
> that it shouldn't contain any in the first is a waste of resources ... this
> does assume that you can trust the data source ... which in the case of a 
> database
> that you control should be the case.

I used to think like that too, but I've relatively recently changed my
position.

While it's not as extreme an example, I used to keep data in the
database *after* I had processed it with htmlspecialchars() (not quite
the same as strip_tags, but the principle is the same).

The issue I had was that over time, I've found the need to output to
other formats - e.g. spread sheets, plain text emails, PDFs etc. in
which case this pre-encoded format is a pain and I have to call
html_entity_decode() to reverse the htmlspecialchars() I did in the
first place. This is a royal pain in the bum and it's really ugly in the
code, remembering what format the data is in in order to process it
appropriately at the right points.

Nowadays I work rather differently and always escape at the point of
output (this does not exclude filtering at the point of input too, but I
do not keep things encoded any longer - I keep it raw).

Any half way decently designed caching layer will prevent any major
impact from escaping at the point of output anyway.

Now you could argue that encoding at the save point and reversing the
encoding when needed is still a better approach and I wont argue too
heavily, but for the sake of my sanity I'm much happier working the way
I do now. The view layers are very clearly escaping everything that
needs escaping and no logic for the "is it or is it not already escaped"
leaks into this layer.

(I appreciate strip tags and htmlspecialchars are not the same and my
general usage may not apply to a pure striptags usage).

> at any rate, strip_tags() doesn't belong in an 'anti-sql-injection' routine as
> it has nothing to do with sql injection at all.

Indeed, it's more about XSS and CSRF rather than SQL injection.

Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Uninstalling PHP?

2010-02-28 Thread Colin Guthrie
'Twas brillig, and Austin Powers at 27/02/10 23:08 did gyre and gimble:
> ""Austin Powers""  wrote in message 
> news:ca.b0.29124.619a8...@pb1.pair.com...
>> Three weeks ago I was working through the Lynda.com "PHP with MySQL
>> Training" because I wanted to begin using PHP (surprise, surprise).
>>
>> Anyway, on this video course the teacher explains that because installing
>> PHP and MySQL is so well understood on a Mac that we may as well just 
>> follow
>> his steps and do it manually.  Well, he is installing a different version 
>> of
>> PHP and MySQL to the ones that I was able to download and while what he 
>> was
>> saying way somewhat similar I am guessing that  there is a difference
>> somewhere, and (well) it's not working.
>>
>> I AM A COMPLETE NOVICE WITH LINUX/FREEBSD.  It had not been my intention 
>> to
>> learn the intricacies of Linux.  However, I am now neck deep in a mire of
>> confusion that even MAMP can't seem to sort out for me.
>>
>> It is purely a guess that I need to start again from a complete clean 
>> setup
>> (reformatting my hard disk and reinstall OS X again) but that is pretty 
>> much
>> out of the question.
>>
>> I guess my question is:
>>
>> "How can I completely uninstall PHP so that I can start again?"
>>
>> Thanks.
>>
> 
> 
> I did a:
> 
>find / -name 'apachectl' 2. /dev/null
> 
> and it came back with:
> 
> /usr/sbin/apachectl
> /Applications/MAMP/Library/bin/apachectl
> 
> so I do:
> 
>cd /Application/MAMP/Library/bin
> 
> and then:
> 
>./apachectl graceful
> 
> and it came back with:
> 
>httpd not running, trying to start
>(13) permission denied: make_sock: could not bind to address {::]:80
>(13 permission denied: make_sock: could not bind to address 0.0.0.0:80
>no listening sockets available, shutting down
>Unable to open logs
> 
> Does this mean that httpd is not running, and that I need to make some 
> change to the httpd.conf file?  If so, then what changes do I need to make? 

You are probably not privileged enough (as a user) to do this. You
likely want to pass it through "sudo" first.

e.g. sudo ./apachectl graceful.

You should be prompted for you *user* password. If you user is allowed
to administer the machine, you should become root temporarily and run
the command.

If you run several sudo commands in relatively quick succession, you
wont have to type your password in again.

Col



-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Enforce a constant in a class.

2010-01-25 Thread Colin Guthrie
'Twas brillig, and Richard Quadling at 22/01/10 11:33 did gyre and gimble:
> Hello,
> 
> One of the aspects of an interface is to enforce a public view of a
> class (as I see it).
> 
> Within PHP, interfaces are allowed to have constants, but you cannot
> override them in a class implementing that interface.
> 
> This seems wrong.
> 
> The interface shouldn't define the value, just like it doesn't define
> the content of the method, it only defines its existence and requires
> that a class implementing the interface accurately matches the
> interface.
> 
> Is there a reason for this behaviour?
> 
> 
> 
> _OR_
> 
> How do I enforce the presence of a constant in a class?
> 
>  interface SetKillSwitch {
>   const KILL_SWITCH_SET = True;
> 
>   // Produces an error as no definition exists.
>   // const KILL_SWITCH_NOTES;
> 
>   // Cannot override in any class implementing this interface.
>   const KILL_SWITCH_DATE = '2010-01-22T11:23:32+';
> }
> 
> class KilledClass implements SetKillSwitch {
>   // Cannot override as defined in interface SetKillSwitch.
>   // const KILL_SWITCH_DATE = '2010-01-22T11:23:32+';
> }
> ?>
> 
> I want to enforce that any class implementing SetKillSwitch also has a
> const KILL_SWITCH_DATE and a const KILL_SWITCH_NOTES.
> 
> I have to use reflection to see if the constant exists and throw an
> exception when it doesn't.
> 
> The interface should only say that x, y and z must exist, not the
> values of x, y and z.

Forgive the perhaps silly question but why are you requiring to use
constants here.

I appreciate the desire to use Reflection but why not just define a
method that must be implemented in the interface?

interface SetKillSwitch {
  public function getKillDate();
  public function getKillNotes();
}


By virtue of something impementing the interface, you know the methods
will exist.

If you want to make implmentation of classes easier, then define and
abstract class with an appropriate constructor and implementation:


abstract class SetKillSwitchAbstract {
  private $_killDate;
  private $_killNotes;
  protected function __construct($killDate, $killNotes)
  {
$this->_killDate = $killDate;
$this->_killNotes = $killNotes;
  }

  public function getKillDate()
  {
return $this->_killDate;
  }

  public function getKillNotes()
  {
return $this->_killNotes;
  }
}


You can either put your "implements SetKillSwitch" in this class or the
derived classes depending on other methods you want to provide in the
base class.


I don't see why constants specifically are needed here. Rather than
using reflection you can just use instanceof or similar to tell if a
given object implements the interface or simply use the interface name
as a type specifier on an argument to another function/method etc.


Col


-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Emergency! Performance downloading big files

2009-12-02 Thread Colin Guthrie

'Twas brillig, and Michael Shadle at 01/12/09 23:51 did gyre and gimble:

On Tue, Dec 1, 2009 at 3:21 PM, James McLean  wrote:


The suggestion from other users of off-loading the PDF downloading to
Apache (or another webserver) is a good idea also.


^

I never allow PHP to be [ab]used and kept open to spoonfeed clients
with fopen/readfile/etc.


I think there has been some confusion The OP wanted a way to 
*download* the files *from* somewhere, not dish them up to his clients.


I think some or the replies were assuming he wanted to have a PHP script 
as a guardian to protect content from unauthorised users but that is not 
what he actually said!



in apache there is a "mod_sendfile" module I think. never used it.


The above said, I didn't know about this module and it looks rather 
useful, so thanks for pointing it out :D


Here is the first Google result I found on this issue which explains it 
a bit.

http://codeutopia.net/blog/2009/03/06/sending-files-better-apache-mod_xsendfile-and-php/

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Is select_db necessary?

2009-08-13 Thread Colin Guthrie
d, then the work you are doing 
on each query is very much real work done in PHP (str_replace, regexp 
matching/replacing, concatenation or whatever).




So perhaps it depends on your view point and preconceptions and we're 
both coming at the "flexible" and "offloading" arguments with different 
starting views.


Anyway, I only asked out of curiosity which I think has been satisfied 
(i.e. ultimately I don't fully agree with you! :p).


Cheers

Col





--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Is select_db necessary?

2009-08-12 Thread Colin Guthrie

'Twas brillig, and Jay Blanchard at 12/08/09 13:53 did gyre and gimble:

Jay Blanchard wrote:

SELECT a.foo, a.bar
FROM myDatabase.myTable a
WHERE you set other conditions here

All that is required is that you establish a connection to a server.


If I recall correctly, this will cause issues with replication in 
MySQL... insofar as you perform amodifying query.

[/snip]

You're correct with regards to queries that modify on replicated
systems. If all you're doing is gathering data then this will work just
fine, is somewhat self-documenting (especially in lengthier code
containers), and very flexible. It also leaves the selection in the
database's hands, and as we almost always say, "let the database do the
work when it can".


I'm interested to know why you consider this to be very flexible and how 
this leaves the selection in the database's hands?


If I were to implement this and they try some destructive testing/demo 
on a sacrificial database, I'd have to use a whole other server instance 
(as all the queries would hardcode in the db name).


Is it not more flexible if you omit the table name in every single query 
and specify it once in your bootstrap/connection code? Thus doing tests 
on other dbs etc. is a pretty simple switch of the connection code.


Also telling the db engine what database you want to use in every query 
is not, IMO, leaving the selection in the the database's hands.


Just curious as to the rationale here :)

Col




--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Upgrading to PHP5.2.x

2009-08-11 Thread Colin Guthrie
'Twas brillig, and Alberto García Gómez at 11/08/09 16:05 did gyre and 
gimble:

Dear Fellows:

I want ot upgrade my PHP from 5.1.x to 5.2.x. I want to do using rpm, but any 
time that I going to upgrade the rpm request me more dependencies.

How can I configure my rpm (or other command) to automaticly satisfy my 
dependencies.


This sounds very much like you are mixing and matching different sources 
of RPMs.


Linux distributions are not like Windows machines where you can just 
install any given application, they are an integrated set of 
interdependant packages.


It is not at all recommended (read: a very bad idea) to install e.g. 
RPMs build for one OS version (e.g. RHEL 5.x) on an older version (e.g. 
RHEL 4.x). Doing so can cause numerous problems due to compiler 
changes/optimisations and small ABI breakages that are incompatible with 
the dynamic libraries used etc.


Even if you do pull in all the dependancies when installing a RHEL5 
version of PHP on RHEL4 (just an example), it will not necessarily work 
for the above reasons.


Similarly, if you do run into problems you will not get any support 
(paid or otherwise) for such a setup.



So please don't undertake this upgrade without fully appreciating what 
is going on. If you really want to install the RHEL5 version on RHEL4 
(again just a random example of a distro), you should download the 
source rpms and rebuild them on RHEL4. You may have to rebuild quite a 
few dependant packages to get a fully working system.


HTHs

Col.

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Array

2009-08-10 Thread Colin Guthrie

'Twas brillig, and Jim Lucas at 10/08/09 16:29 did gyre and gimble:

$d = array(
"home_page",
"member_services",
"member_services_login",
"network",
"resource_center",
"verse_of_the_day_activate",
);


Ahh someone else who always puts a closing , on the end of array 
definitions to cut down on VCS diff/patch churn. Excellent :)


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Dan Brown

2009-08-04 Thread Colin Guthrie

'Twas brillig, and Daniel Brown at 03/08/09 17:29 did gyre and gimble:

my basement office flooded


I think everyone on this list has been inconsiderate to the clearly 
massive tragedy of your flooded basement. May I be the first to pass on 
my condolences for all the dead computers that are now bobbing around 
downstairs.


I hope they've gone to Silicon Heaven.

Sad news indeed.

Col

PS Oh yeah and congrats on the whole baby thing too although it's hardly 
the most poignant story :p


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: 2 ifs embedded? (RESOLVED)

2009-08-01 Thread Colin Guthrie

'Twas brillig, and Miller, Terion at 31/07/09 17:11 did gyre and gimble:

If (ctype_digit($row['critical'])){echo(" Critical violations found: ". 
$row['critical'] .". ");


Remember that empty() does clever stuff for you.

empty('') == true
empty(0) == true
empty('0') == true
empty(1) == false
empty(2) == false
empty('foo') == false

I suspect you were just being bitten by a misconception of what empty() 
was supposed to do when you passed certain values to it.


isset() and empty() are subtly different.

Col




--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Progressbar

2009-06-25 Thread Colin Guthrie

'Twas brillig, and tedd at 24/06/09 15:24 did gyre and gimble:
The biggest problem in uploading a file is figuring out how large it is. 
You can't find that out in php


Well you can find it out with the uploadprogress or APC PECL extensions.

If you use Zend Framework then it has a progress bar for file upload 
built in.


http://www.framework.zend.com/manual/en/zend.file.html#zend.file.transfer.introduction.uploadprogress

HTHs

Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: I've some doubts if I should go with 5.2 or go already with 5.3 (for a course)

2009-06-23 Thread Colin Guthrie

'Twas brillig, and Manuel Aude at 23/06/09 08:38 did gyre and gimble:

I'm giving a PHP course next semester (3 hours all saturdays for 22 weeks)
and I just realized that PHP 5.3 is coming very soon (2 days now!). So, my
plans of teaching PHP 5.2 are starting to change, and I think it's a good
idea to teach them 5.3 already.

While the majority of the students use Windows, I'm aware that a vast amount
will be using Ubuntu/Debian (and some use Gentoo, Fedora and Arch)
distributions of Linux, so I'm hoping there won't be too many problems on
installation. I don't want to waste the entire first class fixing
installation problems, because that kills the student's motivation.

The course starts on August, but I'm preparing it during the last two weeks
of July. You think that installation packages will be bulletproof by then?
Or should I just teach 5.2 and wait for another semester before starting on
5.3? I mean, most hosts will remain with PHP 5.2 for the rest of the year,
so I'm a bit confused on what I should do.


Well I'd imagine the vast majority of your course will be covering the 
basic principles of PHP coding, techniques, GPP, frameworks etc.


Generally most people will want to use a Framework, (Zend, Cake, etc.) 
which will take a while to adopt PHP 5.3 anyway (some still support PHP4 
so what hope is there to use features of PHP5.3 anyway soon!) so I'd 
suggest teaching the basics on a PHP5.x system and then perhaps spend 
two or three sessions at the end covering the newer stuff from PHP 5.3.


That's probably the way I'd go, and you can give people some prior 
warning to try and get a PHP 5.3 install up and running for the x'th 
week of the course.


Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Periodic Actions in PHP?

2009-06-13 Thread Colin Guthrie

'Twas brillig, and Parham Doustdar at 13/06/09 09:42 did gyre and gimble:

Hi there, I'm going to create a small chat script with PHP. The
messages you want others to see will be added to a flat file (I.E.
TXT file), and read and displayed by PHP. However, I want this
reading and displaying to be periodic. This means that I want PHP to
check the file for new lines every,say, fifteen seconds. How may I do
that? I have been unable to find any function that acts like a timer.


For handling periodic tasks in a web environement, I use a little
persistent object (stored using APC) that has it's "process()" method
called on every request. Internally it knows when it was last run and
will actually only do work in it's process() method if it's not been
called for a while.

When this work is done, the user's request is obviously slowed down
slightly, but not in a noticeable way.

If you don't need something this self contained, then a normal cron job 
is needed.



All that asside, I'm not sure you're asking the right question. If 
you've got a chat system, then the client side is presumable a web 
server. You can't really push information from the server side to the 
client, so you really need to pull it from the client side. Usually 
you'd have a javascript timeout that submits an ajax request to the 
server and displays any new messages to the user. In this case, PHP 
doesn't need to be timed, the client is pulling periodically so it's the 
client that sets the timer.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: SHOULD I NOT USE "ELSE" IN IF STATEMENTS....?

2009-06-09 Thread Colin Guthrie

'Twas brillig, and O. Lavell at 08/06/09 16:33 did gyre and gimble:

adam.timberlake wrote:


Im reading this post and i donnot understand how i should write my code:
http://www.talkphp.com/absolute-beginners/4237-curly-

brackets.html#post23720

Does it mean that i am to not write else statements in my ifs? or is it
just saying it is something i should avoid to rite better code?

please help me...


I happen to not agree completely with the post, because it seems to 
propose the use of things like "continue", "break" and "return" within 
control structures (the latter as opposed to at the end of a function, 
exclusively). Very bad practice in my opinion. Think of everything that 
has ever been said of "goto", it's just as bad for structured programming.


(however the use of "break" in "switch .. case" statements is an 
unfortunate necessity in PHP)


And in C. And there is nothing inherently *wrong* with goto. Sure it 
*can* lead to less readable code, but by going out of your way to avoid 
it's use can lead to equally unreadable code.


Just like the break statement which is a fundamental part of switch 
statements but also very useful to get out of infinite loops (our old 
favourite for (;;)) etc.


For this reason early return should not be completely discounted out of 
hand as a "bad programming practice" as this is simply not true.


If early return is ugly for you then you can never use other constructs 
in OOP like exceptions. These interrupt the code flow execution in 
interesting ways too (and the same for the whole break and continue 
statements in controlled loops)


So personally I like early return. I use it mostly to cut down brace and 
indentation churn. I try to keep code into 80 cols and if 40 of them are 
used up with indents that doesn't leave much room for the actual code!


I think with any programming structure, you just have to make sure your 
code is clear, obvious and readable. If you've got a function that 
sprawls four+ screenfulls and has returns littered throughout it, then 
this is obviously not very readable. Re-factoring should solve this, but 
just re-factoring to avoid early return will probably do very little to 
improve it's overall readability IMO.


In many cases early return can improve readability.

e.g. consider

$rv = false;
if ($condition)
{
  // ... several pages of code.
}
return $rv;


When reading this function, I *could* be interested in what happens if 
the condition is not met. In this scenario I have to scroll down and 
track where the brace is closed and then follow the code on from there.


Now consider this:

if (!$condition)
  return false;

$rv = false;
// ... several pages of code.
return $rv;

With this code, considering I'm interested in what happens if the 
condition is not met, I can satisfy my curiosity immediately without 
looking further.


In both cases if I was interested in the opposite, it's the same amount 
of tracking to look through the code itself.



As with everything in programming style, this mostly comes down to 
personal preference. So just stick with a style you like :)


People get almost as emotive about this topic as top-posting on mailing 
lists :) I'm not overly fussed. I know what i like and it doesn't offend 
anyone in public :p


HTHs

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Paypal and Php

2009-05-02 Thread Colin Guthrie

'Twas brillig, and Matthieu at 03/05/09 00:01 did gyre and gimble:

Hello,

I'd like to know if somebody already configured a paypal account usin 
php and a mysql database. What are the major things to know when 
starting to code the php code?


I know it's quite a large question but I'd like to know the amount of 
time needed, or if I directly go through a drupal server.


Thanks for your help


There is a discussion going on right now about Zend_Payment and 
Zend_Payment_Gateway_Paypal over on the Zend Framework mailing list. You 
could perhaps use these classes to interact with PayPal?


Proposal and discussion page is here for the overall Zend_Payment concept:
http://framework.zend.com/wiki/display/ZFPROP/Zend_Payment+-+Vadim+Gabriel

But check the zend framework general mailing list archive for better 
information.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: PHP6 return by reference deprecation

2009-05-02 Thread Colin Guthrie

'Twas brillig, and Larry Garfield at 02/05/09 20:00 did gyre and gimble:

On Saturday 02 May 2009 9:30:09 am Colin Guthrie wrote:

'Twas brillig, and Paul M Foster at 02/05/09 06:07 did gyre and gimble:

If this is going away, how do you return things by reference, so as to
ensure a single copy of something (yes, I know the singleton pattern can
be used; I do use it as well; it's more complicated)?

You'll want to use the Singleton design pattern here.

Let's say you're config object is a class.


That's well and good if the thing you want a single copy of is an object.  The 
way objects pass in PHP 5 makes singletons easy.  But I actually just 
developed a system for PHP 5.2 that includes a class that deliberately allows 
a caller to reach in and grab an internal array-based data structure for 
special cases.


class Foo {
  protected $internalConfig = array(...);

  public function &getConfig() {
return $this->internalConfig;
  }
}

$foo = new Foo();
...
$config = &$foo->getConfig();
// Do stuff to $config that wouldn't make sense to do via methods.

So do I understand the OP correctly that is going to break with PHP 6 now?  I 
certainly hope not, as that would be incredibly short sighted and stupid.  
There are plenty of use cases for returning by reference besides making PHP 4 
objects behave correctly.


Use ArrayObject rather than just array. e.g.

class Foo {
  protected $internalConfig;

  public function __construct() {
$this->internalConfig = new ArrayObject(...);
  }

  public function getConfig() {
return $this->internalConfig;
  }
}

http://www.php.net/manual/en/class.arrayobject.php

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: PHP6 return by reference deprecation

2009-05-02 Thread Colin Guthrie

'Twas brillig, and Paul M Foster at 02/05/09 06:07 did gyre and gimble:

If this is going away, how do you return things by reference, so as to
ensure a single copy of something (yes, I know the singleton pattern can
be used; I do use it as well; it's more complicated)?


You'll want to use the Singleton design pattern here.

Let's say you're config object is a class.

Something like this should work very nicely.


class My_Config
{
  private function __construct()
  {
// Whatever you need to do to load the config
  }


  public static function getInstance()
  {
static $instance = null;
if (null === $instance)
  $instance = new self();
return $instance;
  }
}



Then in your code whenever you want to get your config object you would 
call:


$config = My_Config::getInstance();


You'll only every get one object created due to the private constructor 
and which enforces the use of the getInstance() method.


This is a very common design pattern, and is ideally suited to this use 
case.


HTHs

Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Two very useful PHP functions

2009-04-30 Thread Colin Guthrie

'Twas brillig, and Raymond Irving at 30/04/09 03:32 did gyre and gimble:

Hello,

Every so often I have to be using the isset() function to check if a variable 
exists. It would be useful to have something like an ifset() function

Instead of doing this

$v = isset($input) ? $input : $default;

we can do this

$v = ifset($input,$default); 
// returns $input if it exists otherwise it will return $default


We could also do the same for the empty() function. So instead of doing this

$v = empty($input) ? $default : $input;

we can do this

$v = ifempty($input,$default);
// returns $input if it is not empty otherwise it will return $default

What do you think? Can they make it into 5.3?


To be honest, I don't see the compelling need for this.

I don't disagree that the functionality is nice, however I quite like 
the verbose versions as they are clearer to understand without knowing 
an API function.


Also, most of the cases that you would use these functions are with 
input from GET args and the like. Most frameworks provides wrappers for 
this with handy ways to get the defaults etc.


So overall, I can't see this becoming a core PHP feature.

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: PHP task manager

2009-03-31 Thread Colin Guthrie

'Twas brillig, and George Larson at 31/03/09 20:31 did gyre and gimble:

We've got a homebrew ToDo list (task & project) manager / mailer that we're
thinking about replacing with something a little more robust.

Any suggestions?  I saw TaskFreak! on Google but I am curious if there are
any personal recommendations out there.


Well Trac is my personal favourite, but it's in Python.

JotBug is a new PHP system based around the same principles as Trac, but 
written in the Zend Framework.


http://www.jotbug.org/

It's very early days but perhaps it will be something you can get 
involved with?


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: linux sha1sum .vs php sha1

2009-03-20 Thread Colin Guthrie

'Twas brillig, and Per Jessen at 20/03/09 16:06 did gyre and gimble:

bruce wrote:


hi...

doing some testing with linux sha1sum, and php's sha1 function... are
they both supposed to return the same results for the same chunk of
text.

test

file "a.dat" = "1234567890"

linux:
 echo a.dat > sha1sum -t!= php 

any thoughts...


Try "echo -n"


While you've got the right approach, the original command has three (yes 
3!) different problems!!!


1. echo automatically appends a new line. Using echo -n will prevent this.
2. You have a file, echo a.dat will echo the file *name* a.dat not it's 
contents. You probably want to use "cat" instead.

3. You care redirecting (>) rather than piping (|).

So waht you really want is:
cat a.dat | sha1sum

(the -t is not needed).


You can also do:
echo -n "1234567890" | sha1sum

Col





--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Unique User Hashes

2009-02-18 Thread Colin Guthrie

'Twas brillig, and Ian at 18/02/09 07:09 did gyre and gimble:

We dont have registration - its a once off vote anonymously using the hash
in the original email. We dont want registration otherwise it would be much
easier - but this was the best way I could think of without user
registration :/


Do you have to invite people to vote or can anyone come along and cast?

If the former you could email a UUID token to them or similar as part of 
the link. Once that UUID was "spent" it wouldn't allow voting again.


I say UUID as a regular auto-incrementing id would be fairly easy to 
guess ;)


Of course this may not be appropriate in this circumstance.

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: XSLTProcessor help

2009-02-17 Thread Colin Guthrie

'Twas brillig, and Tom Sparks at 17/02/09 15:17 did gyre and gimble:

I have stopped XSLT from rendering out all the text
but I am no further a long getting XSL stylescript  to work
I have been reading w3schools (http://www.w3schools.com/xsl/default.asp )
and XML 1.1 bible 3rd edition ( 
http://www.amazon.com/XML-Bible-Elliotte-Rusty-Harold/dp/0764549863 )
I am at a lost still!!


It looks more or less OK to me...

Infact I tried it via the command line:

My XML:

Hellooo


The XSL is yours from the previous post:

$ xsltproc test.xsl test.xml




vehicle: Hellooo


vehicle: Hellooo


Works fine.

Are you sure you are not doing something odd in the calling code? e.g. 
make sure you are calling transformToXML() properly. Perhaps slap all 
your files somewhere so we can download and test for you.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: ssh2_tunnel

2009-02-17 Thread Colin Guthrie

'Twas brillig, and Gevorg Harutyunyan at 17/02/09 11:55 did gyre and gimble:

Could you please give me short sample of ssh2_tunnel usage.
The only sample that I found was manual sample and I can not understood how
it works.


Not sure this is the right list for this kind of question, so perhaps 
you can give some example?


If I were to take a guess, I'd suggest something like the following.

Say you want to access an HTTP server at your office but it is behind a 
firewall. You can SSH to your office via the command "ssh 
m...@my.office.com" When inside the office you can access your webserver 
via "http://private.office.com/";.


If you wanted to access the office web server on your local machine you 
would do:


ssh -L 8080:private.office.com:80 m...@my.office.com

Then you would point your browser at:
http://localhost:8080/

And you should see your office website.

Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: inset data to multiple tables

2009-02-16 Thread Colin Guthrie

'Twas brillig, and PJ at 16/02/09 19:57 did gyre and gimble:

Questions:
1.  Do we really need the statements - $result1 = mysql_query($sql1,
$db); ? Why? What purpose do they serve?



These statements send your SQL to the server. Without them you are just 
assigning and SQL command to a variable so they are really rather 
important :p




2. How can one use "mysql_insert_id()" to insert data into multiple
tables? Why would you need to insert an id - especially since there are
only 2 fields in the pulblishers table (above) - id (auto-increment) and
publishers? As I ;understand it, when the id field is auto-increment, a
simple

INSERT INTO publishers  (publisher) VALUES ('$publisherIN') works fine (but not 
above)

Can somebody suggest anything? TIA


Short answer, you can't! It's not what it's for!

You have to do your insert first (with mysql_query() as you did above), 
and then call $my_generated_id = mysql_insert_id(); This will fill the 
variable $my_generated_id with the value of the auto_increment field in 
your table from the last call to mysql_query with an INSERT statement.



Also, you are possibly running risks above if you do not properly escape 
your variables:


e.g. You have:

$sql1 = "INSERT INTO authors (first_name, last_name) VALUES 
('$first_nameIN', '$last_nameIN')";


Your examples do not show where the values came from but if it's 
directly from a form post or similar, if I put the value:

 'blah','blah'); DELETE FROM authors;

The query generated could be:
INSERT INTO authors(firstname,lastname) VALUES ('blah','blah'); DELETE 
FROM authors;.


Obviously this is a massive security risk and is generally referred to 
as "SQL Injection Attacks".


You should look into using the function mysql_real_escape_string() to 
escape all your inputs.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re:

2009-02-16 Thread Colin Guthrie

'Twas brillig, and Eric Butera at 16/02/09 20:01 did gyre and gimble:

On Mon, Feb 16, 2009 at 2:58 PM, Colin Guthrie  wrote:

'Twas brillig, and Richard Heyes at 16/02/09 15:04 did gyre and gimble:


Those reply lines are funny.  =)


Can't take credit as I saw someone else with it and *ahem* liberated it. 
I remember reading the source of it at school so it brought a smile... 
Still one of my favourite poems :)


Col

PS: for those who don't know, it's the Jabberwocky by Lewis Carroll:
http://www.jabberwocky.com/carroll/jabber/jabberwocky.html

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: for the security minded web developer - secure way to login?

2009-02-16 Thread Colin Guthrie

'Twas brillig, and Per Jessen at 16/02/09 13:49 did gyre and gimble:

Colin Guthrie wrote:


Yeah the cheap CA's are IMO actually a problem.

I (personally) think we should have a new system for this scenario:

http:// = totally insecure
https:// = secure and to a reasonable degree of trust (e.g. no $12.00
certs!)
httpus:// = secure but no aspect of trust.


Colin, I think you're mixing apples and oranges here - http(s) was never
meant to provide any indication of "trust". Besides, how do you suggest
we distinguish between CAs "with no trust" and CAs "with trust"?


Well you're probably right.

I appreciate that https doesn't provide "trust" by default, but 
ultimately that's how Joe Bloggs public has been told to deal with it 
"look for the padlock" etc. etc. to be sure that your session is secure 
blah blah. Now with the HV certs the UI also has the company name in the 
URL and this *is* going towards a trust infrastructure.


Perhaps where we should go is that even if the URL is https:// there is 
no UI change in the browser. Only if the cert is trusted by a CA should 
the browser UI change to indicate this in some way, with HV certs being 
explicitly indicated as such to increase the "trust" aspect.


That way you can use https + self singed cert without getting any 
warnings but also without any disadvantages too.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re:

2009-02-16 Thread Colin Guthrie

'Twas brillig, and Richard Heyes at 16/02/09 15:04 did gyre and gimble:

...


Sorry, should've mentioned, I'm talking about PHP6.


Not heard about it but I'd like it. Short tags are evil but the thing is pretty handy so having a 

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: for the security minded web developer - secure way to login?

2009-02-16 Thread Colin Guthrie

'Twas brillig, and Michael A. Peters at 16/02/09 00:10 did gyre and gimble:

Colin Guthrie wrote:

'Twas brillig, and German Geek at 15/02/09 22:32 did gyre and gimble:
Please enlighten me why it is so expensive? Is it maybe just the 
hassle of

setting it up?


The whole thing is about trust. Getting a certificate is nothing if 
the system is not backed up by a trust system. If a CA was setup that 
gave out certificates willy nilly to all and sundry, then this element 
of trust is lost.


Cheap CA's do exist. They have crappy web sites and send you all kinds 
of junk mail etc. if you use them - but they do exist.


I might end up just paying godaddy - I think they charge $12.00 / year, 
but since I already register through them, they already have my address 
etc.


Yeah the cheap CA's are IMO actually a problem.

I (personally) think we should have a new system for this scenario:

http:// = totally insecure
https:// = secure and to a reasonable degree of trust (e.g. no $12.00 
certs!)

httpus:// = secure but no aspect of trust.

httpus:// would support SSL in exactly the same way as https but the UA 
would simply not display the URL any differently to a standard http 
connection. This would give responsible developers the ability to 
provide SSL services where they only really care about the pipe and not 
the trust aspect.


The problem with the cheap certs is that people do not see much 
difference to the expensive ones and this leads to the possibility of 
being hijacked. The weakest link is always the end user not knowing any 
better. The High Validation certs used by big companies at least show up 
differently in FF now but if you were to replace it with a hijacked non 
HV cert, there is still a good chance most users would still use it.


Sadly this isn't going to work without browser support tho' and that's 
very unlikely to happen at all.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: XSLTProcessor help

2009-02-16 Thread Colin Guthrie

'Twas brillig, and Tom Sparks at 16/02/09 10:49 did gyre and gimble:

help, when I include 
the XSLTProcessor only strips the XML tags and outputs the text see result




--cut here vehicle.xsl-

http://www.w3.org/1999/XSL/Transform";>






XSL needs to know that you are outputting XML-derived data...

eg. try putting this before your :

  omit-xml-declaration="yes"/>



Col



--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: for the security minded web developer - secure way to login?

2009-02-15 Thread Colin Guthrie

'Twas brillig, and German Geek at 15/02/09 22:32 did gyre and gimble:

Please enlighten me why it is so expensive? Is it maybe just the hassle of
setting it up?


The whole thing is about trust. Getting a certificate is nothing if the 
system is not backed up by a trust system. If a CA was setup that gave 
out certificates willy nilly to all and sundry, then this element of 
trust is lost. For $1 you're not likely to be able to afford to do much 
in the way of vetting or confirmation that said person is who they say 
they are. If browsers trusted that CA and an unscrupulous individual 
manages to get a secure certificate for a domain they do not own they 
could then use some form of DNS hijacking (e.g. via an open wireless 
network or similar) to perform some pretty convincing phishing scams.


So it's not just about the cert. It's the trust that goes with it.

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: spl_object_hash not hashing unqiue objects BUG

2009-02-12 Thread Colin Guthrie

'Twas brillig, and Jochem Maas at 12/02/09 12:47 did gyre and gimble:

Colin Guthrie schreef:

'Twas brillig, and Nick Cooper at 12/02/09 11:38 did gyre and gimble:

Outputs:

a1: 09d264fcececf51c822c9382b40e3edf
a2: 45701af64172cbc2a33069dfed73fd07
a3: 09d264fcececf51c822c9382b40e3edf
a4: 09d264fcececf51c822c9382b40e3edf

Thanks let me know how I should proceed with this.

Confirmed here. I get different hashes, but the same pattern:

a1: 79eff28a9757f1a526882d82fe01d0f3
a2: 4cec55f17563fe4436164f438de7a88c
a3: 79eff28a9757f1a526882d82fe01d0f3
a4: 79eff28a9757f1a526882d82fe01d0f3

PHP 5.2.9RC1 with Suhosin-Patch 0.9.6.3 (cli) (built: Feb  9 2009 16:00:42)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies

You should report the bug:
http://bugs.php.net/


it's not a bug. RTFM


Yup I meant to retract my statement after reading your reply but my 
message hadn't come through yet to the list and I then got distracted by 
something or other.


In fairness tho' I did RTFM for the function itself and the stuff you 
quoted wasn't listed there, so the docu could do with a little 
clarification on that point.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: spl_object_hash not hashing unqiue objects BUG

2009-02-12 Thread Colin Guthrie

'Twas brillig, and Nick Cooper at 12/02/09 11:38 did gyre and gimble:

Outputs:

a1: 09d264fcececf51c822c9382b40e3edf
a2: 45701af64172cbc2a33069dfed73fd07
a3: 09d264fcececf51c822c9382b40e3edf
a4: 09d264fcececf51c822c9382b40e3edf

Thanks let me know how I should proceed with this.


Confirmed here. I get different hashes, but the same pattern:

a1: 79eff28a9757f1a526882d82fe01d0f3
a2: 4cec55f17563fe4436164f438de7a88c
a3: 79eff28a9757f1a526882d82fe01d0f3
a4: 79eff28a9757f1a526882d82fe01d0f3

PHP 5.2.9RC1 with Suhosin-Patch 0.9.6.3 (cli) (built: Feb  9 2009 16:00:42)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies

You should report the bug:
http://bugs.php.net/

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: APC problem with PHP

2009-02-11 Thread Colin Guthrie

'Twas brillig, and Nathan Nobbe at 11/02/09 00:10 did gyre and gimble:

a lot of php extensions are not thread safe, perhaps apc is one of them.
most people compile apache w/ mpm_prefork rather than mpm_worker for this
reason.


I know the problem is solved now but I think APC is pretty solid 
threading wise. It has various locking mechanisms that you can compile 
in to APC, including filelocks, IPC semaphores, spinlocks and pthread 
mutexes.


So while I don't want to comment inaccurately, I suspect that APC is 
pretty solid in this area.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Throwing an exception seems to defeat output buffering

2009-02-03 Thread Colin Guthrie

'Twas brillig, and Leif Wickland at 03/02/09 06:02 did gyre and gimble:

I would expect that if I turn on output buffering, echo something,
throw an exception,
and catch the exception, nothing will have been actually output.  That
doesn't seem
to be the case.  Throwing an exception seems to defeat output buffering.

In the following code, I would not expect to see the , but I do.



You should not see this!';
throw new Exception('This should be the first output.');
exit( 'Contents: ' . ob_get_clean());
}
catch (Exception $ex) {
exit('Exception:' . $ex->getMessage());
}



I'm exercising that code on PHP 5.2.4 and 5.2.8.

Does anybody know why throwing an exception seems to override
ob_start(), flushing the buffered output?  Is there a workaround?


This is intended behaviour and just represents the natural application 
flow. Exception handling in PHP does not have any concept of "output 
buffering" and operates in a generic way. You start output buffering but 
you don't explicitly turn it of or clean the contents and thus, when the 
script ends (inside your catch block), it will be automatically flushed 
(displayed).


If you don't want any output, make sure your catch block first calls 
ob_end_clean() before it exits.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: [PROJECT HELP] - JotBug - A Project Management & Issue Tracker written 100% with Zend Framework

2009-01-28 Thread Colin Guthrie

'Twas brillig, and rcastley at 27/01/09 23:26 did gyre and gimble:

I am looking (begging!) for help/testing/feedback etc etc etc on my JotBug
project


Looks interesting.

I do hack a bit on Trac, but much prefer PHP (and ZF) to Python (just 
what I know etc.)


That said I've got too much invested in Trac (and the plugins I wrote) 
to jump ship right now.


I wish you all the best of luck tho', and I'll monitor this to see what 
progress you make :)


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Zend Framework...where to start? -- do

2009-01-15 Thread Colin Guthrie

'Twas brillig, and Daevid Vincent at 14/01/09 21:39 did gyre and gimble:
The pages are significantly slower than straight PHP by orders of 
magnitude: http://paul-m-jones.com/?p=315


Shock News: Frameworks that allow you to write an application in less 
code do stuff in the background for you.


I don't mean to state the very obvious but of course frameworks will be 
slower than a simpler and less flexible/powerful/maintainable solution.


That's like buying an F1 car for your daily commute to work then 
complaining about the MPGs you get!


Frameworks are not about running faster, they are about implementing 
faster and more efficiently, using a standard technique that allows 
other developers to take over from you later with minimal hand over, 
it's about being able to take on new staff without having to train them 
in all your specific code etc.


One of the things these speed tests totally fail to take into 
consideration is that any sensibly written application will have a 
caching structure at it's core and will utilise it *heavily*. When an 
application is written with a good caching policy/infrastructure, the 
performance as a whole goes up by orders of magnitude.


Some performance shootouts don't even employ opcode caches which is just 
insane in any kind of sensible hosting environment.


In short, don't believe the hype and use a little bit of logic and 
common sense to make comparisons as to which approach is "better" 
(remember "better" != "raw performance") for you.


Col


PS FWIW, I have adopted Zend_Framework and while some of the paradigms 
don't fully suit me I have extended and adapted them to make it work 
very well for me.


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: FirePHP -- pretty cool

2009-01-11 Thread Colin Guthrie

'Twas brillig, and Skip Evans at 11/01/09 19:19 did gyre and gimble:

Hey Nitsan & all,

I haven't been through it all, I just installed the plug in and download 
the file to include and started using it.


I would imagine you have to use their log function to get any output, 
but it seems like the kind of thing that could be left in the code 
without any ill-affect.


I wrote a wrapper in my global functions file, and I suppose if I wanted 
to turn it off I'd just have that function return at the top.


So far I'm finding it useful and easy enough to use.

If you don't want to change your code I would imagine something like 
xdebug would be the next step.


If you use the Zend Framework it has a log target to this already. For 
production releases you would use a dummy logger. This still has code 
overhead but it's one of those load vs. benefits tradeoffs.


If you really want it to be efficient, you can format your code in such 
a way that a script would process your files and comment out all the log 
calls. Depends whether it's worth the effort to do this really!


Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Unique Object Instance ID..?

2009-01-10 Thread Colin Guthrie

'Twas brillig, and Nathan Rixham at 10/01/09 23:31 did gyre and gimble:
all I need is a completely unique id for each object instance that can 
never be repeated at any time, even in a multiserver environment (and 
without using any kind of incremented value from a db table or third 
party app)


thoughts, ideas, recommendations?


While it's not guaranteed to be unique the general technique used in 
these situations is to use a UUID. The chances of a clash are slim 
(2x10^38 ish combinations).


You can generate a uuid via mysql "SELECT UUID()" or via the PHP Pecl 
extension php-uuid.


The other way of doing it would be to insert a row into a database row 
with an auto-increment field and use the value of that auto-incrment 
field as your identifier (SELECT LAST_INSERT_ID() in mysql or via the db 
layers API).


HTHs

Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Zend framework

2008-12-24 Thread Colin Guthrie

'Twas brillig, and Al at 24/12/08 17:51 did gyre and gimble:



Richard Heyes wrote:

2008/12/24 Al :

I've not given it much thought, so far.

But, am curious about what you folks think about it.

Anyone with experience have a comment?


On what? The Zend Framework?


Sorry, I wasn't clear.  Anyone with experience using the Zend framework, 
in general or any particular components,  have a comment?


Well I use it and like it very much. It takes a while to get your head 
round, or rather the programming methodologies and the related "best 
practices" do (especially when you are trying to retro fit it to an 
existing project).


But if you just spend a few days reading through the manual you'll be 
totally fine.


Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: MERRY XMAS

2008-12-24 Thread Colin Guthrie

'Twas brillig, and Jay Blanchard at 24/12/08 12:07 did gyre and gimble:

[snip]
...greetings from around the world
[/snip]

Merry Chrismakwanzica! Happy Festivus!


Indeed. Happy Annual Gift Giving Day (when it comes!) to one and all.

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: ACL Framework / Library

2008-12-24 Thread Colin Guthrie

'Twas brillig, and Bastien Koert at 24/12/08 14:22 did gyre and gimble:

On Wed, Dec 24, 2008 at 9:01 AM, Feris  wrote:


Hi All,
Is there any references for a good ACL framework / library ? I want to
develop one but if there is any available I didn't want to reinvent the
wheel.

Thanks,

Feris



Zend has their ACL as part of the framework

http://framework.zend.com/manual/en/zend.acl.html


+1 on that one. Remember that you don't need to use the whole 
framework... you can just pick out the Zend_Acl stuff easily enough.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Foreign Keys Question

2008-12-12 Thread Colin Guthrie

'Twas brillig, and tedd at 12/12/08 15:16 did gyre and gimble:
My first tendency is to keep everything. After all, memory is cheap and 
access times are always reducing.


While it's true that having a bunch of worthless data doesn't accomplish 
anything and slows the process  of dealing with it. But, technology in 
access times and storage capabilities are getting to the point of making 
the decision to keep/delete worthless data moot.


As such, I think the need for FK deletions will become less and perhaps 
disappear from the language. For some reason, I look upon deletions in 
similar light as renumbering a table's index after deletion of a record 
-- like "what's the point?"


I'm just rambling -- thanks again for your insight.


Rambling is good... I'll continue!

With data retention and data protection laws (something that can vary 
around the world making life for web-based providers like ourselves even 
more complex), I think it is increasingly important that information 
about a given person can be scrubbed very easily. Keeping the data may 
be cheap from a storage/access perspective, but complying with laws and 
regulations can be wearisome and time consuming.


If you FKs are fully up-to-date and have proper cascading you can be 
sure that a simple:

DELETE FROM users WHERE user_id=123;
really will delete all the information you store about that individual.

You just have to look at the hullabaloo over the "deactivated" Facebook 
accounts etc. to realise that hiding or disabling data is not enough in 
many cases.


Food for thought!

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Foreign Keys Question

2008-12-12 Thread Colin Guthrie

'Twas brillig, and tedd at 12/12/08 14:36 did gyre and gimble:
That's neat and a lot more powerful than I thought. It's like following 
a linked list to it's end while removing all traces of the thread.


Exactly


And I understand the "instructor delete" was not intended.


Yeah indeed. I had a db structure in my head and the statement made 
vague sense with that in mind, but it totally failed to leak through my 
hands on to the keyboard :P


There are three main options here:
 * ON DELETE CASCADE (if the FK's referenced table has it's record 
deleted, delete the record here too).


 * ON DELETE RESTRICT (if the FK's referenced table has it's record 
deleted stop that whole transaction - e.g. *prevent* the delete).


 * ON DELETE SET NULL (if the FK's referenced table has it's record 
deleted, set this tables reference to NULL).


All three are useful in different contexts. I use them extensively to 
ensure good data integrity. The trade off on extra load on insert/update 
is IMO well worth it.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Poll of Sorts: Application Frameworks--Zend, Cake etc

2008-12-12 Thread Colin Guthrie

'Twas brillig, and Terion Miller at 12/12/08 13:55 did gyre and gimble:

Thanks for the responses, CakePhp was seemingly very easy for me to catch
on to and get started in (which means its super super easy folks)
unfortunately when I got to the viewing of my files (pretty important) I
couldn't get the IIS (yep I know sucks) to work with it, and I installed a
mod_rewrite.dll for IIS and everything along with setting it to Cakes
"pretty urls" and removing the htdocs, but then it just kept resolving all
urls to the root ... no matter what I changed the path to, and no matter if
I set it only to that directory...so by end of day yesterday I downloaded
the zend and will attempt to see what I can do with it, I want off this
windows box but that isn't going to happen anytime soon ...sigh...


I hate to say but I suspect you'll be in a similar boat with Zend... 
perhaps not, but I certainly make fairly extensive use of rewrite rules 
to direct all my URLs to my main Zend bootstrap.


Just out of curiosity, are you stuck to that specific windows box (e.g. 
is that what you have to host on in a live env?) or is it just that you 
need to use the machine for devel?


Reason I ask is that it's pretty trivial to install Apache, PHP and 
MySQL on windows there are even some packages that make it ultra 
easy to install e.g.:

http://www.apachefriends.org/en/xampp-windows.html

I don't use it personally (thankfully don't use windows unless I'm poked 
with a pointy stick!) but I hear good things.


Col



--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: How serialize DOMDocument object?

2008-12-12 Thread Colin Guthrie

'Twas brillig, and Михаил Гаврилов at 12/12/08 06:23 did gyre and gimble:

How serialize DOMDocument object?


Easiest way is to save it to an XML string and then load it again.

If you want a conveneinet way to store domdocuments in the session, then 
just extend the class and define __sleep and __wakup functions that 
essentially do the save/load for you.


Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Foreign Keys Question

2008-12-11 Thread Colin Guthrie

'Twas brillig, and Chris at 12/12/08 01:20 did gyre and gimble:

Micah Gersten wrote:

Colin Guthrie wrote:

The ON DELETE CASCADE option is key here... "DELETE FROM students
where student_id=1" will remove all traces of that student from the
db... all the course they've attended, all the instructors who have
taught them etc. keeps things nice and tidy without having to put the
structure in your code all over the place.

Col


Why would you want to delete the instructors when deleting the student?


I think he meant the link between the student & instructor (in the 
student_instructor table), not the instructor itself.


lol, indeed, that's what I meant... Sorry I thought it was implied in 
the context!


Say you have the following layouts

instructors: instructor_id, name
students: student_id, name
instructor_students: instructor_id, student_id


This structure would hold a list of instructors and a list of studends 
and also a one to many mapping of instructors to students.


If you delete a student the FK can cascade to the instructor_students 
table and thus delete the records that indicate a given instructor (or 
instructors) taught them.


Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Poll of Sorts: Application Frameworks--Zend, Cake etc

2008-12-11 Thread Colin Guthrie

'Twas brillig, and Terion Miller at 11/12/08 14:56 did gyre and gimble:

Hey Everyone, I am wondering if using a framework such as one of these may
make my life easier, which do any of you use and what has been your
experience with the learning curve of them?
I just put Cake on my local server, basically I want to know which is
easiest? LOL...


Personally I'm a ZF fan, but each to their own.

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Foreign Keys Question

2008-12-11 Thread Colin Guthrie

'Twas brillig, and tedd at 11/12/08 18:46 did gyre and gimble:
As for my "Foreign Keys Question", I think the answer is that it 
enforces rules upon the configuration (i.e., deleting, altering, and 
such), but does not provide any significant service beyond that.


Well that's a fairly significant service in itself. The whole "deleting 
data" case is where FK's have saved me significant amount of coding.


The ON DELETE CASCADE option is key here... "DELETE FROM students where 
student_id=1" will remove all traces of that student from the db... all 
the course they've attended, all the instructors who have taught them 
etc. keeps things nice and tidy without having to put the structure in 
your code all over the place.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: converting a vid with ffmpeg - howto do progress bars?

2008-12-10 Thread Colin Guthrie

'Twas brillig, and Rene Veerman at 10/12/08 23:03 did gyre and gimble:
Well, nowhere can i find the frame count being printed, but there _is_ a 
duration: hh:mm:ss:ms field outputted, and the updating line displays a 
time=seconds.ms (the time in the movie where the encoder is at).


The question remains how to get at that updating output, with exec() you 
get the output after it's done completely.
And there's no way to do partial conversions with ffmpeg, it's all in 
one or nothing..


IIRC you can use popen and just read the output into PHP.

http://uk.php.net/manual/en/function.popen.php

That said, if I were you I'd do this system slightly differently. I'd do 
the submissions via the web, but then do the encoding as a kind of 
daemon process/cron job that runs on the server. This cron job would do 
the encoding and update a db table periodically with progress. That way 
you can have a page the user goes to that sees their "job progress".


This way the user's browser will not time out and you wont use up apache 
connections waiting for encodings and also you wont kill your server by 
performing multiple encodes at the same time - with the cron job/daemon 
approach you can control how many jobs are performed at the same time 
and thus limit the load.


Just some thoughts.

Col



--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Convert .docx /.pdf file to .txt

2008-12-06 Thread Colin Guthrie

'Twas brillig, and Jagdeep Singh at 06/12/08 06:46 did gyre and gimble:

Hi!

I need a function to fetch text from docx file, but it is showing formated
characters in output. I was using fopen, fgets etc function .

I want to fetch text from .docx and save it to .txt file Without special
characters (Microsoft formated characters)

Is there any function or an example??


Nothing that I know of built in to PHP (although as docx is just XML 
AFAIK, you could just write an XSLT to extract the content).


You could also shell out to an application that would do it for you.

After about 5 seconds on google I found:

http://sourceforge.net/project/showfiles.php?group_id=235455

If it works or not I have no idea!

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Accessing the 'media' attribute in php

2008-12-03 Thread Colin Guthrie

'Twas brillig, and Ashley Sheridan at 03/12/08 08:15 did gyre and gimble:

Whatever you do, don't have a separate
page for "print view". This is one of those things that some bright
spark thought to do on a site at work, and the site in question was
already a couple hundred HTML pages, so he effectively doubled that
figure. It makes your work harder in the long run if you need to update
it at any time, and with the media="print" attribute set for the extra
stylesheet, it's automatically selected anyways.


While I don't want to disagree with the print media option (it's my 
preferred route), depending on your application/use case etc, having a 
separate print layout could make sense.


Say you have a content management system that displays an "entry" over 
several small pages. If you want to print out details of that "entry" it 
may make sense to combine the salient details from all the mini-pages 
into one "printable" page.


If your application is designed well, then this approach certainly 
doesn't double your number of "pages" (from a maintenance perspective). 
If you have a 1000 "entries" each with 5 mini-pages and you add a print 
version you are changing the number from 5 to 6, not 5000 to 6000.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Memcached as Session Handler

2008-11-10 Thread Colin Guthrie

APseudoUtopia wrote:

Hey list,

I run a website that integrates MemCache, MySQL, and PHP sessions very
heavily. I recently came across some documentation on the PHP site
that informs me that I can use MemCache as the session.save_handler,
instead of files.

I know there would be no redundancy of the session data with this type
of setup, in the event that the MemCache daemon fails.

However the website is run on a single server and a single MemCache
daemon, with a single IDE HDD.

I'm curious as to if anyone else uses MemCache as the
session.save_handler? What are the pros and cons of doing this? I
figured it would help out with disk I/O and overall performance
because MemCache would be much faster than the IDE drive, and I
update/reference the $_SESSION data very often.


Well I use it in a multi-server environment. While I don't technically 
need it in this setup it certainly can help in some circumstances. If 
you want to expand to a dual server with round-robin DNS load balancing, 
then memcache will defo help.


No idea about benchmarks and performance vs files tho' so can't really 
help with that!


Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: PHP / Procmail / MIME decoder, Imagemagick, MySQL, PDF fax management system

2008-11-10 Thread Colin Guthrie

Ashley Sheridan wrote:

This may sound a bit of a strange question, but why put the fax in a
PDF? I mean, it's a bitmap graphic, so why not just leave it in a bitmap
format?


Most fax systems I've seen deal with TIFF images but they can be in a 
slightly weird format (missing lines, requiring stretching or something 
like that). Putting the data into PDF is trivial (this is done 
automatically by hylafax system IIRC).


Also it seems Dan's issue is not converting it in PDF format, as he gets 
the data sent to him in PDF already.



For the email decoding, as Richard said, the PEAR MimeDecode classes do 
a fair job of this.


Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: It's Sunday, and I'm bored...

2008-11-09 Thread Colin Guthrie

Jochem Maas wrote:

you're not 'loose' the asylum is just bigger than you realise ... most people
know it by it's other name ... Earth.


Yeah the "outside" of the Asylum is pretty small...  if you don't 
believe me, ask Wonko the Sane...


So long :p

Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: PHP and Cyrus problem

2008-11-07 Thread Colin Guthrie

Richard Heyes wrote:

...PHP for webmail.


Did you know you can use Gmail for webmail, even having the From:
address set to your own domain? It will require a little more setup
(well, with ten thousand mailboxes that would be "a lot") but you end
with one of the best webmail clients there is.


While this is a little off topic there are lots of reasons not to do 
this. For one, the IMAP support in GMail, while very welcome, does have 
different paradigms than traditional email systems. I actually prefer 
the GMail approach of labels rather than "real" folders, but until this 
is exported as part of the IMAP protocol and clients like thunderbird 
support and are aware of it, it's sadly quite clunky to work with. 
(things like copying/moving mails is bit of a headfuk cos you're not 
really copying them, you're labeling them and it shouldn't be purged 
from the inbox, because the inbox is just a "new mail" filter etc. etc.


As the original problem showed a IMAP+Webmail solution, I'd imagine IMAP 
support and a dedicated client is important.



Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: PHP and Cyrus problem

2008-11-07 Thread Colin Guthrie

Emerson Virti wrote:

Where is the problem?


Probably not the right list, but have you tried using cyradm and 
running: reconstruct user.name.mailbox.name


(correct the folder as needed).

When a cyrus database file gets corrupted or generally borked this fixes 
it 99% of the time for me.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: PHP XSLT caching

2008-10-27 Thread Colin Guthrie

vladimirn wrote:

I have one simple question, actually i am interested in your point of view.
Is there any sense in caching xslt itself? If so, then why? If not, then
again why? :)
I think that there is no sense, and that xslt output should be cached.
What do you think?


From your original context it wasn't clear whether you wanted to cache 
the dom document *object* that represents the xslt or the output of the 
transfer after it is applied.


As I explained, (and I think I'm still correct in this), storing the 
object would be kinda pointless as it would have to be serialized to 
string form and then re-parsed on wakeup. Doing this rather than 
reloading from disk again, will save a minor amount of IO and thus time, 
but the saving will be minimal.


So IMO caching the xslt is not worth the effort. Cache the output of the 
transform and load the xslt only when needed.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: PHP XSLT caching

2008-10-26 Thread Colin Guthrie

vladimirn wrote:

Thank you Col
I will go into Zend_Cache as you suggested.
One more thing- does Zend_Cache saces data into file or use a server memory?


As I said in my original mail, but perhaps wasn't clear, Zend_Cache can 
support file, memcache, APC and other backends.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: PHP XSLT caching

2008-10-26 Thread Colin Guthrie

vladimirn wrote:

Hi all,
i was wondering whats the best approach to do next.
I have an xml file delivered from service of my partner. On my web server 
(windows) i have xslt files used for xml transformation. 
Those files are getting bigger, so i have request to cash them and use

cashed. I was thinkging about memcahce php(dunno if it will work on windows
server and tbh never used it before).
So i am sure that there must be several ways to cash xslt files. I google
for this, but i am not sure that i found any solution i can use.
What would be the best approach to solve this? I just would like to see more
ideas :)
LOL sure, if someone already have a good working solution i would appreciate
any link or code :0)


Well you have to define what you actually want to do do here as it's a 
little unclear from your description.


Do you want to cache the XSLT files themselves or do you want to cache 
the result of *applying* the XSLT files to the input XML?


If you just want to cache the XSLT itself (e.g. loaded into a DOM 
document object) then there is little point as you would have to 
serialize and deserialize the dom document objects before storing them 
(via extending the class and adding __sleep() and __wakeup() methods) as 
I am pretty sure Dom Document doesn't do this automatically (last I 
checked which was admittedly a while ago!).


This only saves a small amount of overhead.

If you are looking for a good set of classes that can handle generic 
caching, I'd strongly recommend using the Zend_Cache system.

http://www.framework.zend.com/manual/en/zend.cache.html

Zend cache will support disk-based caching and memcache or APC too all 
via the same API.


Col





--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Replacing with f*ck and f*cking

2008-10-26 Thread Colin Guthrie

Ashley Sheridan wrote:

What you really need to watch out for is words which you're going to
censor which might be part of other names. Sex is an obvious one, as it
appeared in the borough name of my old address: Middlesex.


I can't believe you didn't use the infamous "Scunthorpe" as your example :p

Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: PHP/mySQL question using ORDER BY with logic

2008-10-24 Thread Colin Guthrie

Robert Cummings wrote:

On Fri, 2008-10-24 at 00:18 -0400, Rob Gould wrote:

Question about mySQL and PHP, when using the mySQL ORDER BY method...


	Basically I've got data coming from the database where a "wine  
producer-name" is a word like:


Château Bahans Haut-Brion

or

La Chapelle de La Mission Haut-Brion

or

Le Clarence de Haut-Brion

but I need to ORDER BY using a varient of the string:

	1)  If it begins with "Château", don't include "Chateau" in the  
string to order by.
	2)  If it begins with "La", don't order by "La", unless the first  
word is "Chateau", and then go ahead and order by "La".



	Example sort:  Notice how the producer as-in comes before the  
parenthesis, but the ORDER BY actually occurs after a re-ordering of  
the producer-string, using the above rules.


Red: Château Bahans Haut-Brion (Bahans Haut-Brion, Château )
	Red: La Chapelle de La Mission Haut-Brion (Chapelle de La Mission  
Haut-Brion, La )

Red: Le Clarence de Haut-Brion (Clarence de Haut-Brion, Le )
Red: Château Haut-Brion (Haut-Brion, Château )
Red: Château La Mission Haut-Brion (La Mission Haut-Brion, Château )
	Red: Domaine de La Passion Haut Brion (La Passion Haut Brion,  
Domaine de )

Red: Château La Tour Haut-Brion (La Tour Haut-Brion, Château )
Red: Château Larrivet-Haut-Brion (Larrivet-Haut-Brion, Château )
Red: Château Les Carmes Haut-Brion (Les Carmes Haut-Brion, Château )


	That logic between mySQL and PHP, I'm just not sure how to  
accomplish?  I think it might involve a mySQL alias-technique but I  
could be wrong.


Right now, my PHP call to generate the search is this:

$query = 'SELECT * FROM wine WHERE MATCH(producer, varietal,  
appellation, designation, region, vineyard, subregion, country,  
vintage) AGAINST ( "' . $searchstring . '")  ORDER BY producer LIMIT  
0,100';


Maybe there's a good way to do it with the table as is... but I'm
doubtful. I would create a second field that contains a pre-processed
version of the name that performs stripping to achieve what you want.
This could be done by a PHP script when the data is inserted into the
database, or if not possible like that, then a cron job could run once
in a while, check for entries with this field empty and generate it.


Yeah I'd suspect that the storage overhead is nothing compared to the 
speed increase you'll get during the read operations if you don't have 
to "dick around" with the data :)


(yes I'm comparing bits to time, but I don't have time to explain that bit).


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Politics

2008-10-23 Thread Colin Guthrie

Daniel P. Brown wrote:

 Mandriva Linux Contributor [http://www.mandriva.com/]


Hooray for Cooker!


:D

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Politics

2008-10-23 Thread Colin Guthrie

Daniel P. Brown wrote:

On Thu, Oct 23, 2008 at 11:40 AM, Robert Cummings <[EMAIL PROTECTED]> wrote:

On that note... has anyone seen Lars and the Real Girl? I thought it was
going tobe a comedy after I laughed so hard at the introduction. Then it
was all drama :/


And I missed it all while I was in the hospital.  Internal
bleeding is overrated.  Some day I'll have to check the archives.


Ohh dear, doesn't sound like fun :s Hope you're on the mend now.

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: XCache, APC, Memcached... confused

2008-10-23 Thread Colin Guthrie

Stut wrote:

On 23 Oct 2008, at 00:04, Martin Zvarík wrote:
I am looking at the eAccelerator's website and I realize what got me 
confused:


there is a function for OUTPUT CACHE, so it actually could cache the 
whole website and then run out of memory I guess...


that means I would be able to store anything into the memory and 
reference it by a variable? are the variables accessible across the 
whole server? I still don't really understand, but I am trying...


Having never used eAccelerator I can only guess, but it sounds like it's 
a way to cache HTML output. As for how accessible that is I have no 
idea. I suggest you find the eAccelerator mailing list, subscribe to 
that and ask your question there.


If you are looking into caching things in a very flexible way I'd look 
at the Zend_Cache API from the Zend Framework.


It has backedns to connection to APC and Memcache and also implements a 
disk-based caching system. You can cache all sorts of output, from 
function calls (both return value and side-effect output), html output 
and arbitrary objects.


Using an opcode cache is generally a good idea (part of the APC core 
will be included in PHP6, which is why I'm currently backing that 
particular horse), but for an application-level caching strategy, I 
think Zend_Cache has a lot going for it :)


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Singletons

2008-10-22 Thread Colin Guthrie

Carlos Medina wrote:


this is the Result of my test with your Code:

Fatal error: Access level to Singleton::__construct() must be public (as 
in class Base) in C:\Users\cmedina\Documents\test1.php on line 30


Hmmm, that'll learn me for not running it first I sps :s

Well that is completely crap. I didn't realise there was such a 
limitation in PHP's object heirarchy. Wonder why it's like this... Can't 
think of a valid reason...


Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: Singletons

2008-10-22 Thread Colin Guthrie

Stut wrote:

On 20 Oct 2008, at 20:24, Christoph Boget wrote:

 public function __construct()

A singleton would usually have a private constructor to prevent
non-singleton instances.


The problem being if the class in question derives from another class
that has a public constructor...  If you are in that particular
situation (which I am), you're basically SOL and the statement above
has no bearing.


Correct, but you're then breaking one of the rules of the singleton 
pattern. If you're stuck with that then you'll need to enforce the 
singleton aspect in non-technical ways (policy, regular beatings, etc).



I disagree (not with the regular beatings... that's very important for 
moral!), but with the statement that says you are SOL if you want to 
create a singleton that derives from another class with a public 
constructor, you just have to make the derived class' constructor 
private and call the parent's constructor:



class Base
{
  private $foo;
  public function __construct($foo)
  {
$this->foo = $foo;
  }

  public function getFoo()
  {
return $this->foo;
  }
}

class Singleton extends Base
{
  private function __construct()
  {
parent::__construct("Singleton");
  }

  public static function getInstance()
  {
static $instance = null;
if (!isset($instance))
  $instance = new self();
return $instance;
  }
}


$bar = Singleton::getInstance();
$bar->getFoo(); // "Singleton"


(entirely untested)

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: 1 last error to fix before the application is done!

2008-10-15 Thread Colin Guthrie

Jochem Maas wrote:

Colin Guthrie schreef:

  if(!empty($_SESSION['userInfo']['loggedin'])) {


if (Sess::userLoggedIn()) { /* ... :-) */ }



Well, yes, that's how I do it in my apps too, but in internally in that 
function you may want to use the empty() call :)


I agree that when checking for values other than boolean and such you 
need to do more checks but quite often in practical coding, I find that 
using empty cuts down quite a lot on function call overhead and double 
statements.


Everyone's different tho' so each to their own way :)

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: 1 last error to fix before the application is done!

2008-10-14 Thread Colin Guthrie

Andrew Ballard wrote:

I've heard that a lot, but I just don't see it. I'm sure some of you
can come up with better tests than this, but here is what I used:


...

Based on these results, I'd hardly use the "language construct versus
function call" optimization argument to make my decision. I'm not sure
if this is a testament to improvements in the PHP engine over the last
couple years, or if equipment has gotten fast enough that the
differences have become irrelevant. Quite possibly, it's both.


There are a couple of issues with those benchmarks...
1. It uses rand()... this is generally a bad thing in benchmarks
2. It uses internal (wall clock) timing and tests different things in 
the same application run.

3. 50k iterations is easy! Give it something hard :)

You should really use an external timing function (like "time blah" on 
*nix) as it shows you real processor time used, as well as wall-clock time.



I've posted a simple benchmark else where on this thread that tests 
which prove that for a two index-depth test, !empty is approx 4.5x 
faster than the equiv array_key_exists tests.


Even for a single depth array test, I still get ~3x speed improvement 
using empty() vs. array_key_exists().


Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: 1 last error to fix before the application is done!

2008-10-14 Thread Colin Guthrie

Yeti wrote:

Personally, I very rarely see the point in using array_key_exists... It's a 
function call and has overhead where as isset() and empty() are language 
constructs and (I would hope) are much more efficient (although I've not done 
any benchmarks)


# i don't know what's wrong with this ..

$foo = array();
$foo['bar'] = null;
if (array_key_exists('bar', $foo)) {
 switch ($foo['bar']) {
  case true:
   //do something
   break 1;
  default:
   //do something else
}
}

# if that's causing more overhead then let me see your benchmark, then
i believe it


I don't really get what you're trying to say here.

All I'm saying is that empty(), as a language construct, should be more 
efficient than the resulting function call overhead when using 
array_key_exists().


As I highlighted in my previous example, the only way to test of an 
array has an index which is set to null is to use the array_key_exists() 
function as both isset() (also a language construct) and empty() will 
not be able to tell you this.


So your example above (which sets an array index to null) is the only 
way to do what you want to do (the switch() is overkill for an if/else 
scenario but that's beside the point).



All I was saying was that for an array index value that is set to a 
known true/false value, or not set at all, using !empty() to test for 
when the value is true is the most efficient way.


Consider the following two attached test cases to check for a true 
value, two indexes deep in the array. One uses two calls to 
array_key_exits and then a comparison, the other uses !empty(). They are 
functionally equivalent but the results speak for themselves:


[EMAIL PROTECTED] 0.11]$ time php test1.php
Done: 1000
13.76user 0.01system 0:14.08elapsed 97%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+2805minor)pagefaults 0swaps
[EMAIL PROTECTED] 0.11]$ time php test2.php
Done: 1000
3.06user 0.03system 0:03.13elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+2797minor)pagefaults 0swaps


And a repeat for random variations:

[EMAIL PROTECTED] 0.11]$ time php test1.php
Done: 1000
14.58user 0.05system 0:14.77elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+2805minor)pagefaults 0swaps
[EMAIL PROTECTED] 0.11]$ time php test2.php
Done: 1000
3.01user 0.01system 0:03.06elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+2797minor)pagefaults 0swaps


There's a benchmark for you (not sure if it's the one you wanted) which 
proves that the !empty() is ~4.5x faster.


 Use !empty() :p

Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


test1.php
Description: application/php


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

[PHP] Re: BarcodeDB.com - a Barcode Database

2008-10-14 Thread Colin Guthrie

Alex Chamberlain wrote:

I wish to set up a similar website. Indexed on the modern EAN-13 (used
across the world, and includes ISBNs), the database will store a barcode and
name for *every* product. Additionally, the description of the product can
be stored. In the future, I would like to implement a 'tag-type' system,
whereby a tag, consisting of name (eg Author) and value (eg JK Rowling), can
be assigned to one or more objects. These tags could include links to
publicly available images etc. The country of registration of each product
can be derived from the barcode itself.


While not directly relevant the best book-specific system in this area 
I've seen is:

http://www.librarything.com/

It allows you to hook up a barcode scanner and scan in your books pretty 
quickly. It's quite nice.




I know a very basic database is easy to setup - I did it in a day or two,
but I am struggling with the user management side, including the
authentication of API access, as well as how to implement a 'pending' list.
Has anybody got any ideas?? Is there any (free) software out there capable
of this?? If anybody else wishes to contribute to this very young project, I
am open to ideas ([EMAIL PROTECTED]). Hosting is sorted and I own
BarcodeDB.com and .co.uk


I personally perfer the "API Key" approach where a user will generate an 
API key that is linked to their user account and can be embedded into 
remote applications etc. A simple interface to generate and revoke API 
keys should be available somewhere within your application.


You can then use this API key in your requests as you see fit. An API 
key would typically take the form of a UUID (try SELECT UUID(); in mysql)


It's obviously open to snooping and other such nefarious acts and if you 
want to do a more stringent test you should use some form of digest 
authentication which will require two way communication.


If this is too complex, running your API over SSL should cut down on the 
snooping risk and grabbing the API keys.


The good thing about using API keys like this is you can setup various 
things in your app as you see fit, like a TTL (time to live) or specific 
(i.e. restricted) permissions assigned to different API keys generated 
by a user.


Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: 1 last error to fix before the application is done!

2008-10-14 Thread Colin Guthrie

Peter Ford wrote:

You can probably short-circuit some of that - for example if
$_SESSION['userInfo']['loggedIn'] is only ever set to TRUE (and is not set
otherwise) then you might find that

if (isset($_SESSION['userInfo']['loggedin'])) {


As I mentioned elsewhere on this thread, !empty(..) is a better way of 
doing this as it works in the case when the value is set to FALSE too.


Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: 1 last error to fix before the application is done!

2008-10-14 Thread Colin Guthrie

Jason Pruim wrote:

Or, seeing as I'm a stickler for compact code:

if(!empty($_SESSION['userInfo']['loggedin'])) {

empty() is like isset() but tests for all sorts of "empty" cases ('', 
false, null and 0 are all considered, "empty").


Hey Colin,

Does the ! reverse the empty in this case? such as !empty = not empty?


Yes. That's what the ! always does. It's the "not" operator in PHP (and 
most languages):


http://uk3.php.net/manual/en/language.operators.logical.php

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: 1 last error to fix before the application is done!

2008-10-14 Thread Colin Guthrie

Yeti wrote:

You might also want to try array_key_exists

if (array_key_exists('loggedin', $_SESSION['userInfo'])) {
// do something with $_SESSION['userInfo']['loggedin']
}


You'd first need to check that the key 'userInfo' existed in the 
$_SESSION array too.


Personally, I very rarely see the point in using array_key_exists... 
It's a function call and has overhead where as isset() and empty() are 
language constructs and (I would hope) are much more efficient (although 
I've not done any benchmarks).


There are cases where you may want to use array_key_exists where isset() 
and empty() would fail, e.g.


$arr['foo'] = null;

isset($arr['foo']) == false
!empty($arr['foo']) == false
array_key_exists('foo', $arr) == true

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



[PHP] Re: 1 last error to fix before the application is done!

2008-10-14 Thread Colin Guthrie

Jochem Maas wrote:

Jason Pruim schreef:

Good morning everyone!

I think I might be having a "to early in the morning/not enough
caffeine" moment... But I am down to 1 error on my timecard application
that I would like to clean up. It's a small undefined index error, and
the program works jsut fine the way it is, but why leave an error if you
don't need to? :)

Here is the error:

[Tue Oct 14 08:19:47 2008] [error] PHP Notice:  Undefined index: 
userInfo in

/Volumes/RAIDer/webserver/Documents/dev/stimecard/inc/function/authentication.func.php
on line 22

and here is the relevant code:

==> Line 22if($_SESSION['userInfo']['loggedin'] == TRUE) {
   


if(isset($_SESSION['userInfo']['loggedin']) && 
$_SESSION['userInfo']['loggedin'] == TRUE) {


Or, seeing as I'm a stickler for compact code:

  if(!empty($_SESSION['userInfo']['loggedin'])) {

empty() is like isset() but tests for all sorts of "empty" cases ('', 
false, null and 0 are all considered, "empty").


Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



Re: [PHP] Re: 37 Pictures the World must see

2008-10-04 Thread Colin Guthrie

Thiago Melo de Paula wrote:

What all this stuff have related to PHP?!?
Please, don't use this list to spam


Have you even read this list before??? I've not seen your name here 
before and I've posted and contributed quite a bit over the last few 
years so have a right to the odd indulgence on what is generally a nice 
mix of technical advice, assistance and discussion with a strong social 
side to it.


While I'm not sure that Alex meant to post to the list, I thought it 
would be worth pointing out to those that were intrigued by it what it 
actually was. I think I was doing a service here.


Also the TED.com website is an interesting resource for people involved 
in technical industries and while it's not directly related to PHP, many 
people interested in PHP would be interested in it and I felt it was 
worth pointing that out.


So please don't think what I have to say spam without actually taking a 
little time to consider it.


Col



--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



  1   2   3   4   5   6   >