Re: [PHP] What's the best way to make a dynamic plugin architecture?

2012-08-31 Thread Mark
On Tue, Aug 28, 2012 at 1:43 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Tue, Aug 28, 2012 at 1:16 AM, Larry Garfield la...@garfieldtech.com 
 wrote:
 On 8/27/12 6:11 PM, Matijn Woudt wrote:

 You should never be calling require() yourself.  Just follow the PSR-0
 naming standard and use an autoloader, then you don't have to even think
 about it.  There are many existing autoloaders you can use, including
 Composer's, Symfony2's, and probably Zend has one as well.


 I believe there's one in PHP by default now called SPLClassLoader or
 something like that..

 - Matijn


 There was a proposal for one, but it was never added.  You still need a
 user-space class loader for PSR-0, but they're readily available.


 --Larry Garfield


 Ah thanks for the info. I heard about it way back and assumed it was
 implemented by now ;)

 - Matijn

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


I did some searching on that one since it sounds interesting. It's
laying dormant in bugzilla: https://bugs.php.net/bug.php?id=60128 (the
RFC : https://wiki.php.net/rfc/splclassloader)
Thanks for the advice so far. I will certainly implement Autoloading.
Why didn't i think of that :p Guess my PHP knowledge is a bit rusty
since i did make autoloaders before.

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



Re: [PHP] What's the best way to make a dynamic plugin architecture?

2012-08-28 Thread Matijn Woudt
On Tue, Aug 28, 2012 at 1:16 AM, Larry Garfield la...@garfieldtech.com wrote:
 On 8/27/12 6:11 PM, Matijn Woudt wrote:

 You should never be calling require() yourself.  Just follow the PSR-0
 naming standard and use an autoloader, then you don't have to even think
 about it.  There are many existing autoloaders you can use, including
 Composer's, Symfony2's, and probably Zend has one as well.


 I believe there's one in PHP by default now called SPLClassLoader or
 something like that..

 - Matijn


 There was a proposal for one, but it was never added.  You still need a
 user-space class loader for PSR-0, but they're readily available.


 --Larry Garfield


Ah thanks for the info. I heard about it way back and assumed it was
implemented by now ;)

- Matijn

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



Re: [PHP] What's the best way to make a dynamic plugin architecture?

2012-08-27 Thread Stuart Dallas
On 26 Aug 2012, at 19:42, Mark mark...@gmail.com wrote:

 Envision the following plugin architecture:
 
 class PluginLoader
 {
 }
 
 interface PluginInterface
 {
 .. some function definitions ..
 }
 
 class PluginOne implements PluginInterface
 {
 }
 
 class PluginTwo implements PluginInterface
 {
 }
 
 The PluginLoader is loading the plugins.
 The PluginInterface defines an interface which each plugin has to implement.
 PluginOne and PluginTwo are plugins that implement the interface.
 
 Each plugin (PluginOne and PluginTwo) are stored in their own folders.
 So the folder structure would be somewhat like this:
 |- Plugins
 |- - PluginOne
 |- - - PluginOne.php
 |- - - other possible files
 |- - PluginTwo
 |- - - PluginTwo.php
 |- - - other possible files
 |- PluginLoader.php
 |- PluginInterface.php
 
 Now making this structure isn't an issue. I can do all of that just
 fine. The place where i'm actually going to make a plugin instance is
 where things get a little more complicated. The PluginLoader simply
 reads all the dirs in the Plugins folder and tries to find a filename
 with the same dir. So if it reads the dir Plugins/PluginOne it will
 try to include the PHP file: Plugins/PluginOne/PluginOne.php. That's
 fine and working.
 
 To actually make a plugin instance i can do two things that i know of:
 1. use eval like so: eval('$obj = new '.$pluginName.'();'); and
 register it to the PluginLoader.

No need to use eval, you can simply do this:

$obj = new $pluginName();

See here: http://php.net/language.variables.variable

 2. Let the plugin itself (so in this case PluginOne.php) open itself
 and register it to the PluginLoader.
 
 With the first option i have to do eval which i try to avoid if possible.
 With the second solution the PluginLoader probably has to be a singlethon.

Why does it need to be a singleton?

 Now my question is: what is the right way of loading plugins like
 this? Is there some other option then the two i described above? My
 PHP limitations are the newest version so no limitation there :)
 I'm kinda leaning towards the second option now since that seems to be
 quite stable and not very error prone. The eval one is much easier to
 break :p

If you're happy for each plugin to be in a separate directory then what you 
have in option 1, minus the eval, will work perfectly well. I don't know what 
your use case is but if there's a chance a single plugin might want to provide 
several classes then I'd require an init.php in each plugin folder and have 
that register the class names with the class loader. It could also then pass 
along some meta information such as a description of what each class does. If 
this is for use in web requests you might want to stick to what you currently 
have as there's a lot less overhead.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

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



Re: [PHP] What's the best way to make a dynamic plugin architecture?

2012-08-27 Thread Mark
On Mon, Aug 27, 2012 at 12:41 PM, Stuart Dallas stu...@3ft9.com wrote:
 On 26 Aug 2012, at 19:42, Mark mark...@gmail.com wrote:

 Envision the following plugin architecture:

 class PluginLoader
 {
 }

 interface PluginInterface
 {
 .. some function definitions ..
 }

 class PluginOne implements PluginInterface
 {
 }

 class PluginTwo implements PluginInterface
 {
 }

 The PluginLoader is loading the plugins.
 The PluginInterface defines an interface which each plugin has to implement.
 PluginOne and PluginTwo are plugins that implement the interface.

 Each plugin (PluginOne and PluginTwo) are stored in their own folders.
 So the folder structure would be somewhat like this:
 |- Plugins
 |- - PluginOne
 |- - - PluginOne.php
 |- - - other possible files
 |- - PluginTwo
 |- - - PluginTwo.php
 |- - - other possible files
 |- PluginLoader.php
 |- PluginInterface.php

 Now making this structure isn't an issue. I can do all of that just
 fine. The place where i'm actually going to make a plugin instance is
 where things get a little more complicated. The PluginLoader simply
 reads all the dirs in the Plugins folder and tries to find a filename
 with the same dir. So if it reads the dir Plugins/PluginOne it will
 try to include the PHP file: Plugins/PluginOne/PluginOne.php. That's
 fine and working.

 To actually make a plugin instance i can do two things that i know of:
 1. use eval like so: eval('$obj = new '.$pluginName.'();'); and
 register it to the PluginLoader.

 No need to use eval, you can simply do this:

 $obj = new $pluginName();

 See here: http://php.net/language.variables.variable

Ahh right, i completely forgot about that option. That might just work
the way i want it :)

 2. Let the plugin itself (so in this case PluginOne.php) open itself
 and register it to the PluginLoader.

 With the first option i have to do eval which i try to avoid if possible.
 With the second solution the PluginLoader probably has to be a singlethon.

 Why does it need to be a singleton?

Well, i would then do something like this from within the included
plugin file after the class:
PluginLoader::getInstance()-registerPlugin(new PluginOne());

Or something alike.

 Now my question is: what is the right way of loading plugins like
 this? Is there some other option then the two i described above? My
 PHP limitations are the newest version so no limitation there :)
 I'm kinda leaning towards the second option now since that seems to be
 quite stable and not very error prone. The eval one is much easier to
 break :p

 If you're happy for each plugin to be in a separate directory then what you 
 have in option 1, minus the eval, will work perfectly well. I don't know what 
 your use case is but if there's a chance a single plugin might want to 
 provide several classes then I'd require an init.php in each plugin folder 
 and have that register the class names with the class loader. It could also 
 then pass along some meta information such as a description of what each 
 class does. If this is for use in web requests you might want to stick to 
 what you currently have as there's a lot less overhead.

Yeah, if i extend it more that will certainly be an requirement.

 -Stuart

 --
 Stuart Dallas
 3ft9 Ltd
 http://3ft9.com/

Thank you for your advice, really appreciated.

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



Re: [PHP] What's the best way to make a dynamic plugin architecture?

2012-08-27 Thread Stuart Dallas
On 27 Aug 2012, at 14:29, Mark mark...@gmail.com wrote:

 On Mon, Aug 27, 2012 at 12:41 PM, Stuart Dallas stu...@3ft9.com wrote:
 On 26 Aug 2012, at 19:42, Mark mark...@gmail.com wrote:
 
 2. Let the plugin itself (so in this case PluginOne.php) open itself
 and register it to the PluginLoader.
 
 With the first option i have to do eval which i try to avoid if possible.
 With the second solution the PluginLoader probably has to be a singlethon.
 
 Why does it need to be a singleton?
 
 Well, i would then do something like this from within the included
 plugin file after the class:
 PluginLoader::getInstance()-registerPlugin(new PluginOne());
 
 Or something alike.

I'm not sure I see what PluginLoader is doing? It makes more sense to me if you 
register like so:

PluginLoader::getInstance()-registerPlugin('PluginOne');

Then you get an instance of the plugin:

$plugin = PluginLoader::getInstance()-factory('PluginOne');

Tho, even then I don't see what the PluginLoader is adding to the party.

 Thank you for your advice, really appreciated.


No probs.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

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



Re: [PHP] What's the best way to make a dynamic plugin architecture?

2012-08-27 Thread Mark
On Mon, Aug 27, 2012 at 3:46 PM, Stuart Dallas stu...@3ft9.com wrote:
 On 27 Aug 2012, at 14:29, Mark mark...@gmail.com wrote:

 On Mon, Aug 27, 2012 at 12:41 PM, Stuart Dallas stu...@3ft9.com wrote:
 On 26 Aug 2012, at 19:42, Mark mark...@gmail.com wrote:

 2. Let the plugin itself (so in this case PluginOne.php) open itself
 and register it to the PluginLoader.

 With the first option i have to do eval which i try to avoid if possible.
 With the second solution the PluginLoader probably has to be a singlethon.

 Why does it need to be a singleton?

 Well, i would then do something like this from within the included
 plugin file after the class:
 PluginLoader::getInstance()-registerPlugin(new PluginOne());

 Or something alike.

 I'm not sure I see what PluginLoader is doing? It makes more sense to me if 
 you register like so:

 PluginLoader::getInstance()-registerPlugin('PluginOne');

 Then you get an instance of the plugin:

 $plugin = PluginLoader::getInstance()-factory('PluginOne');

 Tho, even then I don't see what the PluginLoader is adding to the party.

Well, i'm making the classes up as i type. I don't actually have a
PluginLoader yet. Or rather, i'm just beginning to make it right now.
What it's doing is very simple. Read through the directory of the
plugins and load every single plugin it finds in memory. Then every
plugin registers the mime types it can handle. That information is
stored in the PluginLoader upon which some other place can call:
PluginLoader::pluginForMime(text/html). Though i still have to take
a good look at that.

But you're right, i can use the factory pattern here.

 Thank you for your advice, really appreciated.


 No probs.

 -Stuart

 --
 Stuart Dallas
 3ft9 Ltd
 http://3ft9.com/

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



Re: [PHP] What's the best way to make a dynamic plugin architecture?

2012-08-27 Thread Stuart Dallas
On 27 Aug 2012, at 14:52, Mark mark...@gmail.com wrote:

 On Mon, Aug 27, 2012 at 3:46 PM, Stuart Dallas stu...@3ft9.com wrote:
 On 27 Aug 2012, at 14:29, Mark mark...@gmail.com wrote:
 
 On Mon, Aug 27, 2012 at 12:41 PM, Stuart Dallas stu...@3ft9.com wrote:
 On 26 Aug 2012, at 19:42, Mark mark...@gmail.com wrote:
 
 2. Let the plugin itself (so in this case PluginOne.php) open itself
 and register it to the PluginLoader.
 
 With the first option i have to do eval which i try to avoid if possible.
 With the second solution the PluginLoader probably has to be a singlethon.
 
 Why does it need to be a singleton?
 
 Well, i would then do something like this from within the included
 plugin file after the class:
 PluginLoader::getInstance()-registerPlugin(new PluginOne());
 
 Or something alike.
 
 I'm not sure I see what PluginLoader is doing? It makes more sense to me if 
 you register like so:
 
 PluginLoader::getInstance()-registerPlugin('PluginOne');
 
 Then you get an instance of the plugin:
 
 $plugin = PluginLoader::getInstance()-factory('PluginOne');
 
 Tho, even then I don't see what the PluginLoader is adding to the party.
 
 Well, i'm making the classes up as i type. I don't actually have a
 PluginLoader yet. Or rather, i'm just beginning to make it right now.
 What it's doing is very simple. Read through the directory of the
 plugins and load every single plugin it finds in memory. Then every
 plugin registers the mime types it can handle. That information is
 stored in the PluginLoader upon which some other place can call:
 PluginLoader::pluginForMime(text/html). Though i still have to take
 a good look at that.
 
 But you're right, i can use the factory pattern here.


Ahh, I see. Personally I'd go with the following (pseudocode)...

Inside the PluginLoader constructor (or other method)
  foreach (plugindir)
require plugindir/plugindir.php
$plugindir::init($this)

The static init() method calls PluginLoader::registerPlugin('mime/type', 
'PluginClassName'). Then pluginForMime does a lookup for the mime type and 
returns an object of the corresponding type. That way a single plugin can 
support multiple mime types.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

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



Re: [PHP] What's the best way to make a dynamic plugin architecture?

2012-08-27 Thread Mark
On Mon, Aug 27, 2012 at 4:26 PM, Stuart Dallas stu...@3ft9.com wrote:
 On 27 Aug 2012, at 14:52, Mark mark...@gmail.com wrote:

 On Mon, Aug 27, 2012 at 3:46 PM, Stuart Dallas stu...@3ft9.com wrote:
 On 27 Aug 2012, at 14:29, Mark mark...@gmail.com wrote:

 On Mon, Aug 27, 2012 at 12:41 PM, Stuart Dallas stu...@3ft9.com wrote:
 On 26 Aug 2012, at 19:42, Mark mark...@gmail.com wrote:

 2. Let the plugin itself (so in this case PluginOne.php) open itself
 and register it to the PluginLoader.

 With the first option i have to do eval which i try to avoid if possible.
 With the second solution the PluginLoader probably has to be a 
 singlethon.

 Why does it need to be a singleton?

 Well, i would then do something like this from within the included
 plugin file after the class:
 PluginLoader::getInstance()-registerPlugin(new PluginOne());

 Or something alike.

 I'm not sure I see what PluginLoader is doing? It makes more sense to me if 
 you register like so:

 PluginLoader::getInstance()-registerPlugin('PluginOne');

 Then you get an instance of the plugin:

 $plugin = PluginLoader::getInstance()-factory('PluginOne');

 Tho, even then I don't see what the PluginLoader is adding to the party.

 Well, i'm making the classes up as i type. I don't actually have a
 PluginLoader yet. Or rather, i'm just beginning to make it right now.
 What it's doing is very simple. Read through the directory of the
 plugins and load every single plugin it finds in memory. Then every
 plugin registers the mime types it can handle. That information is
 stored in the PluginLoader upon which some other place can call:
 PluginLoader::pluginForMime(text/html). Though i still have to take
 a good look at that.

 But you're right, i can use the factory pattern here.


 Ahh, I see. Personally I'd go with the following (pseudocode)...

 Inside the PluginLoader constructor (or other method)
   foreach (plugindir)
 require plugindir/plugindir.php
 $plugindir::init($this)

 The static init() method calls PluginLoader::registerPlugin('mime/type', 
 'PluginClassName'). Then pluginForMime does a lookup for the mime type and 
 returns an object of the corresponding type. That way a single plugin can 
 support multiple mime types.

 -Stuart

 --
 Stuart Dallas
 3ft9 Ltd
 http://3ft9.com/

That sounds sane and i probably go for that :)
Thanks for clarifying it a little.

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



Re: [PHP] What's the best way to make a dynamic plugin architecture?

2012-08-27 Thread Larry Garfield

On 8/27/12 4:09 PM, Mark wrote:

On Mon, Aug 27, 2012 at 4:26 PM, Stuart Dallas stu...@3ft9.com wrote:



2. Let the plugin itself (so in this case PluginOne.php) open itself
and register it to the PluginLoader.

With the first option i have to do eval which i try to avoid if possible.
With the second solution the PluginLoader probably has to be a singlethon.


Why does it need to be a singleton?


Well, i would then do something like this from within the included
plugin file after the class:
PluginLoader::getInstance()-registerPlugin(new PluginOne());

Or something alike.


I'm not sure I see what PluginLoader is doing? It makes more sense to me if you 
register like so:

PluginLoader::getInstance()-registerPlugin('PluginOne');

Then you get an instance of the plugin:

$plugin = PluginLoader::getInstance()-factory('PluginOne');

Tho, even then I don't see what the PluginLoader is adding to the party.


Well, i'm making the classes up as i type. I don't actually have a
PluginLoader yet. Or rather, i'm just beginning to make it right now.
What it's doing is very simple. Read through the directory of the
plugins and load every single plugin it finds in memory. Then every
plugin registers the mime types it can handle. That information is
stored in the PluginLoader upon which some other place can call:
PluginLoader::pluginForMime(text/html). Though i still have to take
a good look at that.

But you're right, i can use the factory pattern here.



Ahh, I see. Personally I'd go with the following (pseudocode)...

Inside the PluginLoader constructor (or other method)
   foreach (plugindir)
 require plugindir/plugindir.php
 $plugindir::init($this)

The static init() method calls PluginLoader::registerPlugin('mime/type', 
'PluginClassName'). Then pluginForMime does a lookup for the mime type and 
returns an object of the corresponding type. That way a single plugin can 
support multiple mime types.

-Stuart

--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/


That sounds sane and i probably go for that :)
Thanks for clarifying it a little.


You should never be calling require() yourself.  Just follow the PSR-0 
naming standard and use an autoloader, then you don't have to even think 
about it.  There are many existing autoloaders you can use, including 
Composer's, Symfony2's, and probably Zend has one as well.


Also, the key question is how you'll be mapping your situation to the 
plugin you need.  If it's fairly hard-coded (i.e., mime type of foo = 
class Bar), then just use a simple dependency injection container like 
Pimple.  If it's more complex and situational, then yes a factory is the 
easiest approach.


--Larry Garfield

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



Re: [PHP] What's the best way to make a dynamic plugin architecture?

2012-08-27 Thread Matijn Woudt
On Tue, Aug 28, 2012 at 12:58 AM, Larry Garfield la...@garfieldtech.com wrote:
 On 8/27/12 4:09 PM, Mark wrote:

 On Mon, Aug 27, 2012 at 4:26 PM, Stuart Dallas stu...@3ft9.com wrote:


 2. Let the plugin itself (so in this case PluginOne.php) open itself
 and register it to the PluginLoader.

 With the first option i have to do eval which i try to avoid if
 possible.
 With the second solution the PluginLoader probably has to be a
 singlethon.


 Why does it need to be a singleton?


 Well, i would then do something like this from within the included
 plugin file after the class:
 PluginLoader::getInstance()-registerPlugin(new PluginOne());

 Or something alike.


 I'm not sure I see what PluginLoader is doing? It makes more sense to
 me if you register like so:

 PluginLoader::getInstance()-registerPlugin('PluginOne');

 Then you get an instance of the plugin:

 $plugin = PluginLoader::getInstance()-factory('PluginOne');

 Tho, even then I don't see what the PluginLoader is adding to the
 party.


 Well, i'm making the classes up as i type. I don't actually have a
 PluginLoader yet. Or rather, i'm just beginning to make it right now.
 What it's doing is very simple. Read through the directory of the
 plugins and load every single plugin it finds in memory. Then every
 plugin registers the mime types it can handle. That information is
 stored in the PluginLoader upon which some other place can call:
 PluginLoader::pluginForMime(text/html). Though i still have to take
 a good look at that.

 But you're right, i can use the factory pattern here.



 Ahh, I see. Personally I'd go with the following (pseudocode)...

 Inside the PluginLoader constructor (or other method)
foreach (plugindir)
  require plugindir/plugindir.php
  $plugindir::init($this)

 The static init() method calls PluginLoader::registerPlugin('mime/type',
 'PluginClassName'). Then pluginForMime does a lookup for the mime type and
 returns an object of the corresponding type. That way a single plugin can
 support multiple mime types.

 -Stuart

 --
 Stuart Dallas
 3ft9 Ltd
 http://3ft9.com/


 That sounds sane and i probably go for that :)
 Thanks for clarifying it a little.


 You should never be calling require() yourself.  Just follow the PSR-0
 naming standard and use an autoloader, then you don't have to even think
 about it.  There are many existing autoloaders you can use, including
 Composer's, Symfony2's, and probably Zend has one as well.


I believe there's one in PHP by default now called SPLClassLoader or
something like that..

- Matijn

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



Re: [PHP] What's the best way to make a dynamic plugin architecture?

2012-08-27 Thread Larry Garfield

On 8/27/12 6:11 PM, Matijn Woudt wrote:


You should never be calling require() yourself.  Just follow the PSR-0
naming standard and use an autoloader, then you don't have to even think
about it.  There are many existing autoloaders you can use, including
Composer's, Symfony2's, and probably Zend has one as well.



I believe there's one in PHP by default now called SPLClassLoader or
something like that..

- Matijn


There was a proposal for one, but it was never added.  You still need a 
user-space class loader for PSR-0, but they're readily available.


--Larry Garfield

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



[PHP] What's the best way to make a dynamic plugin architecture?

2012-08-26 Thread Mark
Hi,

Envision the following plugin architecture:

class PluginLoader
{
}

interface PluginInterface
{
.. some function definitions ..
}

class PluginOne implements PluginInterface
{
}

class PluginTwo implements PluginInterface
{
}

The PluginLoader is loading the plugins.
The PluginInterface defines an interface which each plugin has to implement.
PluginOne and PluginTwo are plugins that implement the interface.

Each plugin (PluginOne and PluginTwo) are stored in their own folders.
So the folder structure would be somewhat like this:
|- Plugins
|- - PluginOne
|- - - PluginOne.php
|- - - other possible files
|- - PluginTwo
|- - - PluginTwo.php
|- - - other possible files
|- PluginLoader.php
|- PluginInterface.php

Now making this structure isn't an issue. I can do all of that just
fine. The place where i'm actually going to make a plugin instance is
where things get a little more complicated. The PluginLoader simply
reads all the dirs in the Plugins folder and tries to find a filename
with the same dir. So if it reads the dir Plugins/PluginOne it will
try to include the PHP file: Plugins/PluginOne/PluginOne.php. That's
fine and working.

To actually make a plugin instance i can do two things that i know of:
1. use eval like so: eval('$obj = new '.$pluginName.'();'); and
register it to the PluginLoader.
2. Let the plugin itself (so in this case PluginOne.php) open itself
and register it to the PluginLoader.

With the first option i have to do eval which i try to avoid if possible.
With the second solution the PluginLoader probably has to be a singlethon.

Now my question is: what is the right way of loading plugins like
this? Is there some other option then the two i described above? My
PHP limitations are the newest version so no limitation there :)
I'm kinda leaning towards the second option now since that seems to be
quite stable and not very error prone. The eval one is much easier to
break :p

Cheers,
Mark

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



[PHP] Is there a way to customize the 'Username' and 'Password' strings in a 401 auth dialog box?

2012-06-28 Thread Daevid Vincent
Is there a way to customize the 'Username' and 'Password' strings in a 401
auth dialog box?
 
I want to change mine to say Webmaster ID and Authentication Key.
 
http://php.net/manual/en/features.http-auth.php
 


Re: [PHP] Is there a way to customize the 'Username' and 'Password' strings in a 401 auth dialog box?

2012-06-28 Thread David OBrien
On Thu, Jun 28, 2012 at 7:23 PM, Daevid Vincent dae...@daevid.com wrote:

 Is there a way to customize the 'Username' and 'Password' strings in a 401
 auth dialog box?

 I want to change mine to say Webmaster ID and Authentication Key.

 http://php.net/manual/en/features.http-auth.php


This  http://www.ietf.org/rfc/rfc2617.txt says the browser actually
controls the prompts all you get to set is the realm.


Re: [PHP] is there a way to stop HTMLPurifier/CSStidy from forcing input CSS into all lowercase?

2012-06-01 Thread Govinda
 
 You need to get better tools.  I found this with Notepad++ for Windows
 searching case within *.php files filter within the root directory
 of the extracted zip/tarball:
 
  
 H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\Font.php
 (6 hits)
   Line 45: $lowercase_string = strtolower($string);
   Line 46: if (isset($system_fonts[$lowercase_string])) {
   Line 47: return $lowercase_string;
   Line 61: case 0:
   Line 77: case 1:
   Line 131: case 2:
 
 Haven't looked at the entire file or source code but that looks close
 enough to me... ;)

Thanks a lot for taking a look Tommy,

I do have a decent text editor I use to code with... and had searched for 
possible places where is the culprit strtolower() ... and so far no matter 
which instances(s) I comment out, I cannot seem to turn off the behavior of the 
library as a whole (either of them, or both) which is forcing the input CSS to 
lowercase.

For example, I also just tried the exact place you suggested: this one:

[snip]htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\Font.php

...and changed line 45 to this:

//$lowercase_string = strtolower($string);//Govinda hack
$lowercase_string = $string;

but still no luck.


 Have you tried http://htmlpurifier.org/phorum/ and did you noticed
 Since the project has been suspended, please only contact me if you
 intend to continue maintaining it. for CSSTidy?

I hadn't posted on http://htmlpurifier.org/phorum because last time I did that 
when I has also posted on stackoverlfow (SO), then the developer of 
HTMLpurifier scolded me for the dupe ;-) ..  and he has already posted a 
comment on my (this new) SO post, saying just, Hmm, that's silly of CSS Tidy. 
Maybe we should change that default..  I assume he probably has a lot on his 
plate, to the point that his answers are incredibly terse and not necessarily 
very helpful.

I did see the message about CSStidy no longer being developed (if that is the 
meaning behind suspended).  Yet when i was researching it, many people were 
still recommending it.  No?  Do you know/prefer something else for the purpose 
of cleaning user-input CSS bound for an external style sheet?

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



Re: [PHP] is there a way to stop HTMLPurifier/CSStidy from forcing input CSS into all lowercase?

2012-06-01 Thread Tommy Pham
On Thu, May 31, 2012 at 11:17 PM, Govinda govinda.webdnat...@gmail.com wrote:

 You need to get better tools.  I found this with Notepad++ for Windows
 searching case within *.php files filter within the root directory
 of the extracted zip/tarball:

  H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\Font.php
 (6 hits)
       Line 45:         $lowercase_string = strtolower($string);
       Line 46:         if (isset($system_fonts[$lowercase_string])) {
       Line 47:             return $lowercase_string;
       Line 61:                 case 0:
       Line 77:                 case 1:
       Line 131:                 case 2:

 Haven't looked at the entire file or source code but that looks close
 enough to me... ;)

 Thanks a lot for taking a look Tommy,

 I do have a decent text editor I use to code with... and had searched for 
 possible places where is the culprit strtolower() ... and so far no matter 
 which instances(s) I comment out, I cannot seem to turn off the behavior of 
 the library as a whole (either of them, or both) which is forcing the input 
 CSS to lowercase.


Perhaps you should spend some time looking for a better text editor
for your OS. :)  When the current tools I use does not give
satisfactory progress in what I'd like to do, I replace the tool(s).

 For example, I also just tried the exact place you suggested: this one:

 [snip]htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\Font.php

 ...and changed line 45 to this:

        //$lowercase_string = strtolower($string);//Govinda hack
        $lowercase_string = $string;

 but still no luck.


 Have you tried http://htmlpurifier.org/phorum/ and did you noticed
 Since the project has been suspended, please only contact me if you
 intend to continue maintaining it. for CSSTidy?

 I hadn't posted on http://htmlpurifier.org/phorum because last time I did 
 that when I has also posted on stackoverlfow (SO), then the developer of 
 HTMLpurifier scolded me for the dupe ;-) ..  and he has already posted a 
 comment on my (this new) SO post, saying just, Hmm, that's silly of CSS 
 Tidy. Maybe we should change that default..  I assume he probably has a lot 
 on his plate, to the point that his answers are incredibly terse and not 
 necessarily very helpful.

 I did see the message about CSStidy no longer being developed (if that is the 
 meaning behind suspended).  Yet when i was researching it, many people were 
 still recommending it.  No?  Do you know/prefer something else for the 
 purpose of cleaning user-input CSS bound for an external style sheet?

 Thanks
 -Govinda


Are you sure you fixed ALL of the offending lines containing
strtolower?  This is what Notepad++ returns when I search for
strtolower:

Search strtolower (48 hits in 28 files)
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\Background.php
(1 hits)
Line 35: $bits = explode(' ', strtolower($string)); // bits to 
process
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\BackgroundPosition.php
(1 hits)
Line 80: $lbit = ctype_lower($bit) ? $bit : 
strtolower($bit);
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\Color.php
(1 hits)
Line 17: $lower = strtolower($color);
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\Font.php
(1 hits)
Line 45: $lowercase_string = strtolower($string);
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\ListStyle.php
(1 hits)
Line 30: $bits = explode(' ', strtolower($string)); // bits to 
process
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\TextDecoration.php
(1 hits)
Line 19: $string = strtolower($this-parseCDATA($string));
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS.php
(2 hits)
Line 51: $property = strtolower($property);
Line 59: if (strtolower(trim($value)) !== 'inherit') {
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\Enum.php
(2 hits)
Line 7:  *  built-in strtolower and ctype_lower functions, 
which may
Line 40: $string = ctype_lower($string) ? $string :
strtolower($string);
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\HTML\Color.php
(1 hits)
Line 17: if (isset($colors[strtolower($string)])) return
$colors[$string];
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\HTML\LinkTypes.php
(1 hits)
Line 39: $part = strtolower(trim($part));
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\Lang.php
(3 hits)
Line 35: $subtags[0] = strtolower($subtags[0]);
Line 50: if (!ctype_lower($subtags[1])) $subtags[1] =

Re: [PHP] is there a way to stop HTMLPurifier/CSStidy from forcing input CSS into all lowercase?

2012-06-01 Thread Govinda
we got off list, without meaning to, it seems.

Here are  the last few posts in the thread:


 
 On Fri, Jun 1, 2012 at 12:46 AM, Govinda govinda.webdnat...@gmail.com 
 wrote:
 Perhaps you should spend some time looking for a better text editor
 for your OS. :)  When the current tools I use does not give
 satisfactory progress in what I'd like to do, I replace the tool(s).
 
 I am happy with my editor.  It (BBedit) has good multi-file 
 search-replace... and I can also generate that/a full list of where all is 
 strtolower()..  BUT I do not want to just willy nilly comment out/remove 
 all those instances of strtolower(), because even if it seems to work, I 
 won't really know what damage I may have done to the library(ies).  If I 
 can find just the one instance that is the culprit, without spending days 
 trying every single spot, one at a time, then great.. but since a lot of 
 the code in those libraries is a bit over my head (without spending a lot 
 of time on it), I want something more definitive than just stabbing at 
 every strtolower().
 
 I appreciate your time and attention.   When I post my OP, I was/am hoping 
 for a reply where someone knows what really is the situation; where is the 
 specific offending line(s) I can hack in the source, or better yet, just 
 how can we set CSStidy config options through HTMLpurifier at runtime, and 
 so not hack the source at all.
 
 -Govinda
 
 You don't need to modify every strtolower statement.  Just open up the
 files and look at that code block and the surrounding code blocks.  If
 that doesn't make sense, then most likely it's not what you're looking
 for.
 
 
 I tried that..  and some of the instances of strtolower() I thought very 
 well could be the culprit.. and so I commented it out... but it did not help 
 (it was not the culprit, or else it was still being overridden by another 
 one).
 
 Many other instances I could not tell by looking at the code.
 
 Some were pretty clearly not the culprit.
 
  In Notepad++, double clicking on a line in the search results
 window will open up the file and bring you right to that line.  If
 BBedit doesn't do that, then refer back to my comment about the tools
 you use :)  Just my 2 cents.
 
 BBedit too does do that  :-)
 
 
 BTW, I rather dig through the code 1st and see what strength and
 weakness that framework provides and to fully comprehend if all its
 bells and whistles are as others claim.  What may work for others may
 not for you.  For example, in all my past searches for a PHP
 framework, only Yii managed to fulfill the most of what I want in a
 framework, including and specifically ability to create CRUD UI by
 just specifying the table name after the DB configurations are set.
 But more than that, Yii went beyond my expectation by providing the
 client side validation for the CRUD too.  Granted the UI doesn't fit
 my liking but it does more than the other frameworks I've looked at.
 :)
 
 I have been pleased with the frameworks and libraries I have picked to help 
 me out.. even HTMLpurifier and CSStidy have been great.. It was not until 
 now (too deep in to want to go back) that I realized I have this one issue.
 
 I am just about to hand off this code.. just need to find a way to 
 patch/workaround this one thing.. have another new project stating monday.
 
 In case I seem irreverent.. it is not my intention... I appreciate you even 
 bothering to reply :-)
 -Govinda
 
 Have you tried using xdebug and step through the code to look for
 changes?  IIRC, xdebug is capable of monitoring variables and their
 values.

AFAICT that is a brilliant idea -  put a watch on the var(s) until I can trace 
just exactly where the offending line is.  
[snip]
 I have yet to bring my tools up to speed to do that here in PHP.  I won't have 
time before this thing is out the door..   but thanks for reminding me I need 
to check out something like xdebug sooner than later.

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



[PHP] is there a way to stop HTMLPurifier/CSStidy from forcing input CSS into all lowercase?

2012-05-31 Thread Govinda
Hi guys

anyone here using HTMLpurifier and CSStidy together?  (like e.g. to allow users 
to create their own external style sheets via form input)

...for example, in the way this post's answer explains how to use HTMLpurifier 
and CSStidy together:

http://stackoverflow.com/questions/3241616/

If so, do you know how to set CSStidy's config options in that context?

I found how to set CSStidy's config options if I was running CSStidy from the 
command line, or on its _own_ from PHP runtime, but I do not know how to set 
the config options from within HTMLpurifier, or even how to hack/override 
either of those libraries to solve my particular issue.  I looked and hacked 
and thought for sure I would find the offending line of code.. but somehow, 
nothing I have tried is stopping one or both of those libraries from forcing 
all my input CSS into lowercase, which I do not want.  The issue is that I need 
the input CSS's case to be left as the user input it (so that for example 
background image paths in that CSS do not break).

more details, attempted fixes, etc.:
http://stackoverflow.com/questions/10843600/

Thanks for any thoughts/tips of any kind
-Govinda
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] is there a way to stop HTMLPurifier/CSStidy from forcing input CSS into all lowercase?

2012-05-31 Thread Tommy Pham
On Thu, May 31, 2012 at 10:33 PM, Govinda govinda.webdnat...@gmail.com wrote:
 Hi guys

 anyone here using HTMLpurifier and CSStidy together?  (like e.g. to allow 
 users to create their own external style sheets via form input)

 ...for example, in the way this post's answer explains how to use 
 HTMLpurifier and CSStidy together:

 http://stackoverflow.com/questions/3241616/

 If so, do you know how to set CSStidy's config options in that context?

 I found how to set CSStidy's config options if I was running CSStidy from the 
 command line, or on its _own_ from PHP runtime, but I do not know how to set 
 the config options from within HTMLpurifier, or even how to hack/override 
 either of those libraries to solve my particular issue.  I looked and hacked 
 and thought for sure I would find the offending line of code.. but somehow, 
 nothing I have tried is stopping one or both of those libraries from forcing 
 all my input CSS into lowercase, which I do not want.  The issue is that I 
 need the input CSS's case to be left as the user input it (so that for 
 example background image paths in that CSS do not break).

 more details, attempted fixes, etc.:
 http://stackoverflow.com/questions/10843600/

 Thanks for any thoughts/tips of any kind
 -Govinda

Have you tried http://htmlpurifier.org/phorum/ and did you noticed
Since the project has been suspended, please only contact me if you
intend to continue maintaining it. for CSSTidy?

Regards,
Tommy

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



Re: [PHP] is there a way to stop HTMLPurifier/CSStidy from forcing input CSS into all lowercase?

2012-05-31 Thread Tommy Pham
On Thu, May 31, 2012 at 10:48 PM, Tommy Pham tommy...@gmail.com wrote:
 On Thu, May 31, 2012 at 10:33 PM, Govinda govinda.webdnat...@gmail.com 
 wrote:
 Hi guys

 anyone here using HTMLpurifier and CSStidy together?  (like e.g. to allow 
 users to create their own external style sheets via form input)

 ...for example, in the way this post's answer explains how to use 
 HTMLpurifier and CSStidy together:

 http://stackoverflow.com/questions/3241616/

 If so, do you know how to set CSStidy's config options in that context?

 I found how to set CSStidy's config options if I was running CSStidy from 
 the command line, or on its _own_ from PHP runtime, but I do not know how to 
 set the config options from within HTMLpurifier, or even how to 
 hack/override either of those libraries to solve my particular issue.  I 
 looked and hacked and thought for sure I would find the offending line of 
 code.. but somehow, nothing I have tried is stopping one or both of those 
 libraries from forcing all my input CSS into lowercase, which I do not want. 
  The issue is that I need the input CSS's case to be left as the user input 
 it (so that for example background image paths in that CSS do not break).

You need to get better tools.  I found this with Notepad++ for Windows
searching case within *.php files filter within the root directory
of the extracted zip/tarball:

  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\Font.php
(6 hits)
Line 45: $lowercase_string = strtolower($string);
Line 46: if (isset($system_fonts[$lowercase_string])) {
Line 47: return $lowercase_string;
Line 61: case 0:
Line 77: case 1:
Line 131: case 2:

Haven't looked at the entire file or source code but that looks close
enough to me... ;)


 more details, attempted fixes, etc.:
 http://stackoverflow.com/questions/10843600/

 Thanks for any thoughts/tips of any kind
 -Govinda

 Have you tried http://htmlpurifier.org/phorum/ and did you noticed
 Since the project has been suspended, please only contact me if you
 intend to continue maintaining it. for CSSTidy?

 Regards,
 Tommy

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



[PHP] Re: PHPmailer.. best way to send to many recipients?

2010-12-21 Thread Ian
On 20/12/2010 21:33, Govinda wrote:
 followup question, please see below the OP:
 
 I just started using PHPmailer for one project that requires SMTP
 authentication (if I said that right).. and all is well.. but I want
 to ask now before it might get outta hand later:

 How many comma-delim'ed addresses can I stuff in $BCC_recipients
 before I have problems (need to restructure the design)?

 --
 require(php_inc/class.phpmailer.php);
 $mail = new PHPMailer();
 $BCC_recipients = x...@host.com,y...@server.com; // ---just an example
 $arrBCC_recipients = explode(,, $BCC_recipients);
 foreach ($arrBCC_recipients as $email2stuffInBCC) {
 $mail-AddBcc($email2stuffInBCC);
 }
 if(!$mail-Send()) { // problem 
 --

 For now there will be less than 100 Bcc recipients.. but later, more. 
 I don't know if/when it will ever grow past 1,000.
 
 I see from reading on a PHPmailer list that the main concern people
 expressed from this (above) approach is to not go over limits set by the
 host/server as to how many emails can go out before being marked as
 spam.  OK, understood.

 Here I am just asking about the code.  I mean does it make any
 difference in terms of code reliability whether I loop on $mail-Send()
 -versus- looping on/concatenating the Bcc addresses?

Hi,

I regularly use PHPMailer to send out a mailshot to two batches of 5
and had no problems at all.

I would not use BCC.  Just set the recipient, send the email, then use
the ClearAllRecipients() function and start again.

We do other things like set a custom MessageID for tracking bounces and
auto unsubscribing during this process as well.

I also do this from the command line so I don't have to worry about
timeouts / apache memory issues etc.  But as long as you're aware of
these problems then you can set the values appropriately.

Regards

Ian
-- 

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



[PHP] Re: PHPmailer.. best way to send to many recipients?

2010-12-21 Thread Govinda

Hi,

I regularly use PHPMailer to send out a mailshot to two batches of  
5

and had no problems at all.

I would not use BCC.  Just set the recipient, send the email, then use
the ClearAllRecipients() function and start again.

We do other things like set a custom MessageID for tracking bounces  
and

auto unsubscribing during this process as well.

I also do this from the command line so I don't have to worry about
timeouts / apache memory issues etc.  But as long as you're aware of
these problems then you can set the values appropriately.

Regards

Ian
--



Thank you for replying Ian!
That was just what I wanted to hear.. and I really appreciate your  
taking the time to offer me your experience so I can feel secure about  
using the class for multiple recipients.  I'll do as you suggest and  
move the mailing into a proper loop on the send function itself (out  
of Bcc).



Govinda


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



[PHP] Re: PHPmailer.. best way to send to many recipients?

2010-12-20 Thread Govinda

followup question, please see below the OP:

I just started using PHPmailer for one project that requires SMTP  
authentication (if I said that right).. and all is well.. but I want  
to ask now before it might get outta hand later:


How many comma-delim'ed addresses can I stuff in $BCC_recipients  
before I have problems (need to restructure the design)?


--
require(php_inc/class.phpmailer.php);
$mail = new PHPMailer();
$BCC_recipients = x...@host.com,y...@server.com; // ---just an  
example

$arrBCC_recipients = explode(,, $BCC_recipients);
foreach ($arrBCC_recipients as $email2stuffInBCC) {
$mail-AddBcc($email2stuffInBCC);
}
if(!$mail-Send()) { // problem 
--

For now there will be less than 100 Bcc recipients.. but later,  
more.  I don't know if/when it will ever grow past 1,000.


I see from reading on a PHPmailer list that the main concern people  
expressed from this (above) approach is to not go over limits set by  
the host/server as to how many emails can go out before being marked  
as spam.  OK, understood.
Here I am just asking about the code.  I mean does it make any  
difference in terms of code reliability whether I loop on $mail- 
Send() -versus- looping on/concatenating the Bcc addresses?



Govinda





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



RE: [PHP] Use PHP the way God intended...

2010-12-14 Thread Jay Blanchard
[snip]
 Nah, if he'd read it backwards, you'd be able to hear MePHPistoPHPeles
 say, Rasmus is the Penguin.

 (Yes, you have to be dang old to get that obscure reference. ;-)


Pshaw, not *that* old! I get the reference, and I'm only . . . oh, damn.
:(
[/snip]

Uhhyeah

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



Re: [PHP] Use PHP the way God intended...

2010-12-14 Thread Daniel Brown
On Tue, Dec 14, 2010 at 09:29, Robert Cummings rob...@interjinn.com wrote:

 I must have been under a rock when the reference came out :|

Or you may have still been in shock from hearing that Paul was dead.

-- 
/Daniel P. Brown
Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

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



Re: [PHP] Use PHP the way God intended...

2010-12-14 Thread Paul M Foster
On Tue, Dec 14, 2010 at 11:15:59AM -0500, Daniel Brown wrote:

 On Tue, Dec 14, 2010 at 09:29, Robert Cummings rob...@interjinn.com wrote:
 
  I must have been under a rock when the reference came out :|
 
 Or you may have still been in shock from hearing that Paul was dead.

Er... that's Paul McCartney, not Paul Foster. Whew!

Paul

-- 
Paul M. Foster

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



Re: [PHP] Use PHP the way God intended...

2010-12-14 Thread David Harkness
On Tue, Dec 14, 2010 at 8:43 AM, Paul M Foster pa...@quillandmouse.comwrote:

 Er... that's Paul McCartney, not Paul Foster. Whew!


Paul McCartney's dead?? But the Beatles just released a ton of albums on
iTunes! So sad...


Re: [PHP] Use PHP the way God intended...

2010-12-14 Thread Daniel Brown
On Tue, Dec 14, 2010 at 11:43, Paul M Foster pa...@quillandmouse.com wrote:

 Er... that's Paul McCartney, not Paul Foster. Whew!

HA!  Sorry to make your heart jump.  ;-P

-- 
/Daniel P. Brown
Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

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



RE: [PHP] Use PHP the way God intended...

2010-12-13 Thread Daevid Vincent
 

 -Original Message-
 From: Robert Cummings [mailto:rob...@interjinn.com] 
 Sent: Friday, December 10, 2010 6:54 AM
 To: Daevid Vincent
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] ORM doctrine
 
 On 10-12-09 10:41 PM, Daevid Vincent wrote:
  Use PHP the way God intended it to be used.
 
 Could you cite a reference for where God states his intentions on PHP?
 
 Thanks,
 Rob.

I believe it was in the Old PHPestament, 
The Book of Rasmus chapter 42 verse 69...

66  ...
67  And behold as he opened the 5th point 2nd seal 
68  and the Lord said unto him,
69  Thou shalt not use frameworks,
70  for they art cumbersome 
71  and a bastardization of mine own language
72  ...

It goes on to talk about using ?= instead of ?php echo 
And how you should always put the closing ? on the page bottom,
But I digress...

ROFL! :D


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



Re: [PHP] Use PHP the way God intended...

2010-12-13 Thread Robert Cummings

On 10-12-13 07:28 PM, Daevid Vincent wrote:




-Original Message-
From: Robert Cummings [mailto:rob...@interjinn.com]
Sent: Friday, December 10, 2010 6:54 AM
To: Daevid Vincent
Cc: php-general@lists.php.net
Subject: Re: [PHP] ORM doctrine

On 10-12-09 10:41 PM, Daevid Vincent wrote:

Use PHP the way God intended it to be used.


Could you cite a reference for where God states his intentions on PHP?

Thanks,
Rob.


I believe it was in the Old PHPestament,
The Book of Rasmus chapter 42 verse 69...

66  ...
67  And behold as he opened the 5th point 2nd seal
68  and the Lord said unto him,
69  Thou shalt not use frameworks,
70  for they art cumbersome
71  and a bastardization of mine own language
72  ...

It goes on to talk about using ?= instead of ?php echo
And how you should always put the closing ? on the page bottom,
But I digress...

ROFL! :D


*heheh* I think you've been reading it backwards ;)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Use PHP the way God intended...

2010-12-13 Thread Paul M Foster
On Mon, Dec 13, 2010 at 11:04:52PM -0500, Robert Cummings wrote:

 On 10-12-13 07:28 PM, Daevid Vincent wrote:
 
 

[snip]

 
 I believe it was in the Old PHPestament,
 The Book of Rasmus chapter 42 verse 69...
 
 66  ...
 67  And behold as he opened the 5th point 2nd seal
 68  and the Lord said unto him,
 69  Thou shalt not use frameworks,
 70  for they art cumbersome
 71  and a bastardization of mine own language
 72  ...
 
 It goes on to talk about using ?= instead of ?php echo
 And how you should always put the closing ? on the page bottom,
 But I digress...
 
 ROFL! :D
 
 *heheh* I think you've been reading it backwards ;)

Nah, if he'd read it backwards, you'd be able to hear MePHPistoPHPeles
say, Rasmus is the Penguin.

(Yes, you have to be dang old to get that obscure reference. ;-)

Paul

-- 
Paul M. Foster

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



Re: [PHP] Use PHP the way God intended...

2010-12-13 Thread David Harkness
On Mon, Dec 13, 2010 at 8:48 PM, Paul M Foster pa...@quillandmouse.comwrote:

 Nah, if he'd read it backwards, you'd be able to hear MePHPistoPHPeles
 say, Rasmus is the Penguin.

 (Yes, you have to be dang old to get that obscure reference. ;-)


Pshaw, not *that* old! I get the reference, and I'm only . . . oh, damn. :(

David


[PHP] Is there a way to write to the php error log from a php script?

2010-10-22 Thread Tamara Temple
I'm trying to log some data for debugging and don't have use of the  
standard output to do so. I'd like to write the info to the php error  
log. Can this be done from within PHP? I've searched the web site for  
logging functions, but cannot find any.



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



Re: [PHP] Is there a way to write to the php error log from a php script?

2010-10-22 Thread Daniel P. Brown
On Fri, Oct 22, 2010 at 20:24, Tamara Temple tamouse.li...@gmail.com wrote:
 I'm trying to log some data for debugging and don't have use of the standard
 output to do so. I'd like to write the info to the php error log. Can this
 be done from within PHP? I've searched the web site for logging functions,
 but cannot find any.

Sure.  You can use trigger_error() and error_log() for that.

-- 
/Daniel P. Brown
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

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



Re: [PHP] Is there a way to write to the php error log from a php script?

2010-10-22 Thread Tamara Temple


On Oct 22, 2010, at 7:31 PM, Daniel P. Brown wrote:

On Fri, Oct 22, 2010 at 20:24, Tamara Temple  
tamouse.li...@gmail.com wrote:
I'm trying to log some data for debugging and don't have use of the  
standard
output to do so. I'd like to write the info to the php error log.  
Can this
be done from within PHP? I've searched the web site for logging  
functions,

but cannot find any.


   Sure.  You can use trigger_error() and error_log() for that.


Ah, yes, error_log() is precisely what I'm looking for. Seaching for  
log gave me the log function, searching for logging gave me a  
bunch of references I couldn't follow (for some reason the feeds want  
to open in my Mail.app client and create RSS feeds -- less than useful).




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



[PHP] Is the case of ?php important in any way?

2010-04-26 Thread Richard Quadling
Hi.

I've recently come across some third party code which uses ...

?PHP

as the PHP tag.

This is the first time I've seen PHP in upper case for the tag.

The code works in V5, so, from this, I can assume the tag is read case
insensitive.

Are there any issues with this when moving forward?

When Unicode support is re-committed to trunk, does case sensitivity
become part of this?

Regards,

Richard.

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

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



Re: [PHP] Is the case of ?php important in any way?

2010-04-26 Thread Daniel Brown
On Mon, Apr 26, 2010 at 04:51, Richard Quadling
rquadl...@googlemail.com wrote:
 Hi.

 I've recently come across some third party code which uses ...

 ?PHP

 as the PHP tag.

 This is the first time I've seen PHP in upper case for the tag.

 The code works in V5, so, from this, I can assume the tag is read case
 insensitive.

 Are there any issues with this when moving forward?

Glance through some of the user notes on the site and you'll see
that some folks prefer to use UPPER-CASE ?PHP as opposed to
lower-case ?php.  It's always worked just fine.  In fact, I remember
a PHP3 site that someone wrote (.phtml and .php3 files!) that used
UPPER-CASE in every file, including for variables and functions.  I
don't remember having to modify that part to work (but thinking how
much I'd love to break the person's CAPS LOCK off the keyboard
permanently).

 When Unicode support is re-committed to trunk, does case sensitivity
 become part of this?

From this, I gather you meant to send this to Internals, but
still, I wouldn't anticipate any change in case-sensitivity regarding
any part of the engine that hasn't yet required such.  Opening tags,
functions, operators, et cetera.  User-defined things like variables
will be case-sensitive, of course, but only the lamest of the lame
would appreciate otherwise.  ;-P

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
We now offer SAME-DAY SETUP on a new line of servers!

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



Re: [PHP] Is the case of ?php important in any way?

2010-04-26 Thread Richard Quadling
On 26 April 2010 15:08, Daniel Brown danbr...@php.net wrote:
 On Mon, Apr 26, 2010 at 04:51, Richard Quadling
 rquadl...@googlemail.com wrote:
 Hi.

 I've recently come across some third party code which uses ...

 ?PHP

 as the PHP tag.

 This is the first time I've seen PHP in upper case for the tag.

 The code works in V5, so, from this, I can assume the tag is read case
 insensitive.

 Are there any issues with this when moving forward?

    Glance through some of the user notes on the site and you'll see
 that some folks prefer to use UPPER-CASE ?PHP as opposed to
 lower-case ?php.  It's always worked just fine.  In fact, I remember
 a PHP3 site that someone wrote (.phtml and .php3 files!) that used
 UPPER-CASE in every file, including for variables and functions.  I
 don't remember having to modify that part to work (but thinking how
 much I'd love to break the person's CAPS LOCK off the keyboard
 permanently).

 When Unicode support is re-committed to trunk, does case sensitivity
 become part of this?

    From this, I gather you meant to send this to Internals, but
 still, I wouldn't anticipate any change in case-sensitivity regarding
 any part of the engine that hasn't yet required such.  Opening tags,
 functions, operators, et cetera.  User-defined things like variables
 will be case-sensitive, of course, but only the lamest of the lame
 would appreciate otherwise.  ;-P

 --
 /Daniel P. Brown
 daniel.br...@parasane.net || danbr...@php.net
 http://www.parasane.net/ || http://www.pilotpig.net/
 We now offer SAME-DAY SETUP on a new line of servers!


Thanks Dan.



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

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



[PHP] Is there a way to get PHP to release this file?

2010-03-01 Thread Andrew Ballard
I am editing a data file via ODBC, and would like to be able to
download the updated file in the same transaction when finished. It
seems, however, that even after calling odbc_close(), PHP still
retains a lock on the file for the duration of the request. Is there a
way to get PHP to release the file? (Ideally, I'd prefer to work in
memory and/or streams altogether rather than saving the changes to a
file, but I'm not sure that's possible with odbc_connect.) I guess if
I have to I can issue a redirect to a second process that would
download the file, but I'd prefer having to pass a one-time URL to the
browser where it will end up in the history.

Andrew

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



Re: [PHP] What's the best way to extract HTML out of $var?

2010-01-15 Thread Bruno Fajardo
2010/1/15 alexus ale...@gmail.com:
 What's the best way to extract HTML out of $var?

 example of $var

 $var = a href=http://http://stackoverflow.com/Stack Overflow/a
 I want

 $var2 = http://starckoverflow.com/;
 example: preg_match();

 what else?

Hi,
If you simply wants to remove all tags from the string, try using the
strip_tags function (http://php.net/strip_tags).


 --
 http://alexus.org/

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

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



Re: [PHP] What's the best way to extract HTML out of $var?

2010-01-14 Thread John Meyer
On 1/14/2010 7:15 PM, alexus wrote:
 What's the best way to extract HTML out of $var?
 
 example of $var
 
 $var = a href=http://http://stackoverflow.com/Stack Overflow/a
 I want
 
 $var2 = http://starckoverflow.com/;
 example: preg_match();
 
 what else?
 

Actually what it looks like you want are the URLs, not the HTML. This
regular expression will match them up for you:

https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?

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



[PHP] Is there any way to get all the function name being called in a process?

2009-10-23 Thread Satya Narayan Singh
Hi,

I am working on reverse engineering for a web project. I was trying to know
that, is there any way(function by PHP, Zend, extension etc)
to find out how many function has been called to perform a task.

If no, can you suggest is it possible/feasible or not?


Thanks in advance
-- 
Satya
Bangalore.


RE: [PHP] Is there any way to get all the function name being called in a process?

2009-10-23 Thread Andrea Giammarchi

http://uk3.php.net/manual/en/function.get-defined-functions.php
get_defined_functions

Regards

 Date: Fri, 23 Oct 2009 11:54:34 +0530
 From: astra.sat...@gmail.com
 To: php-general@lists.php.net
 Subject: [PHP] Is there any way to get all the function name being called in 
 aprocess?
 
 Hi,
 
 I am working on reverse engineering for a web project. I was trying to know
 that, is there any way(function by PHP, Zend, extension etc)
 to find out how many function has been called to perform a task.
 
 If no, can you suggest is it possible/feasible or not?
 
 
 Thanks in advance
 -- 
 Satya
 Bangalore.
  
_
Keep your friends updated—even when you’re not signed in.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_5:092010

RE: [PHP] Is there any way to get all the function name being called in a process?

2009-10-23 Thread Ashley Sheridan
On Fri, 2009-10-23 at 10:27 +0200, Andrea Giammarchi wrote:

 http://uk3.php.net/manual/en/function.get-defined-functions.php
 get_defined_functions
 
 Regards
 
  Date: Fri, 23 Oct 2009 11:54:34 +0530
  From: astra.sat...@gmail.com
  To: php-general@lists.php.net
  Subject: [PHP] Is there any way to get all the function name being called 
  in a  process?
  
  Hi,
  
  I am working on reverse engineering for a web project. I was trying to know
  that, is there any way(function by PHP, Zend, extension etc)
  to find out how many function has been called to perform a task.
  
  If no, can you suggest is it possible/feasible or not?
  
  
  Thanks in advance
  -- 
  Satya
  Bangalore.
 
 _
 Keep your friends updated—even when you’re not signed in.
 http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_5:092010


That won't do what the OP asked, it will just return a list of all the
functions defined, which could be a lot more than is actually being used
in a process, such as in the case of included libraries of functions.

Would some form of PHP debugger help here? I've not used any debuggers
before, but I would imagine that this is something which could be
achieved quite easily with one.

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




Re: [PHP] Is there any way to get all the function name being called in a process?

2009-10-23 Thread Satya Narayan Singh
Thank a lot.

APD is just doing what I was looking for.




On Fri, Oct 23, 2009 at 5:13 PM, Andrea Giammarchi an_...@hotmail.comwrote:


  That won't do what the OP asked, it will just return a list of all the
  functions defined, which could be a lot more than is actually being used
  in a process, such as in the case of included libraries of functions.

 uhm, right, I guess APD then:
 http://uk3.php.net/manual/en/book.apd.php

 Regards

 --
 Windows Live: Keep your friends up to date with what you do 
 online.http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_1:092010




-- 
Satya
Bangalore.


Re: [PHP] Is there any way to get all the function name being called in a process?

2009-10-23 Thread kranthi
even APD is not up to the task

xdebug trace http://devzone.zend.com/article/2871 is sufficient, but
the output will be in a separate file.

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



Re: [PHP] Is there any way to get all the function name being called in a process?

2009-10-23 Thread Eddie Drapkin
There's xdebug, as mentioned, that'll do it as an extension.

What you REALLY probably are looking for is http://php.net/debug_backtrace

And what kind of reverse engineering would you be doing without
reflection? ( http://php.net/reflection ) ;]

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



RE: [PHP] Is there any way to get all the function name being called in a process?

2009-10-23 Thread Andrea Giammarchi


 even APD is not up to the task
 
 xdebug trace http://devzone.zend.com/article/2871 is sufficient, but
 the output will be in a separate file.



 Thank a lot.
 
 APD is just doing what I was looking for.
 
 -- 
 Satya
 Bangalore.

Regards
  
_
Windows Live: Keep your friends up to date with what you do online.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_1:092010

[PHP] is there any way to get realpath cache hit ratio of php?

2009-08-11 Thread Peter Wang
hi,

Is there any way to get realpath cache hit ratio of php?


realpath_cache_size integer

Determines the size of the realpath cache to be used by PHP. This
value should be increased on systems where PHP opens many files, to
reflect the quantity of the file operations performed.

realpath_cache_ttl integer

Duration of time (in seconds) for which to cache realpath information
for a given file or directory. For systems with rarely changing files,
consider increasing the value.

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



[PHP] is there a way to get more info about *why* the initial (DB PEAR) connect to db is failing?

2009-07-03 Thread Govinda

my code:

require 'DB.php';
// $db=DB::connect('db_program://user:passw...@hostname/database');
	$db=DB::connect('mysql://metheuser:myp...@www.mydomain.com/ 
mydatabase');

if (DB::isError($db)) { die(Can't connect:  . $db-getMessage()); }

is returning:
Can't connect: DB Error: connect failed

Any advise to find out WHY this is failing?
(Note: I am fairly new to PHP, and brand spanking new at anything db- 
related with PHP.)


thanks, Govinda

--

P.S.
I realize this had probably been covered countless times (best step by  
step advice how to troubleshoot the first connection to a mysql db),  
so i first did try to search the php list archives, here:

http://marc.info/?l=php-generalw=2r=1s=db+connectq=b
and I am apparently missing something because when I input
failed db connection
at the top, in the search box, then it returns posts all over the map,  
and also takes out the middle word in my search string (so now it is  
just failed db).  Why is that?
I also searched for failed database connection which does not change  
my search input, but still the posts I found did not give me enough  
clue to stop me from posting here now.


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



Re: [PHP] is there a way to get more info about *why* the initial (DB PEAR) connect to db is failing?

2009-07-03 Thread Phpster





On Jul 3, 2009, at 7:31 PM, Govinda govinda.webdnat...@gmail.com  
wrote:



my code:

   require 'DB.php';
   // $db=DB::connect('db_program://user:passw...@hostname/database');

   if (DB::isError($db)) { die(Can't connect:  . $db-getMessage 
()); }


is returning:
Can't connect: DB Error: connect failed

Any advise to find out WHY this is failing?
(Note: I am fairly new to PHP, and brand spanking new at anything db- 
related with PHP.)


thanks, Govinda

--

P.S.
I realize this had probably been covered countless times (best step  
by step advice how to troubleshoot the first connection to a mysql  
db), so i first did try to search the php list archives, here:

http://marc.info/?l=php-generalw=2r=1s=db+connectq=b
and I am apparently missing something because when I input
failed db connection
at the top, in the search box, then it returns posts all over the  
map, and also takes out the middle word in my search string (so now  
it is just failed db).  Why is that?
I also searched for failed database connection which does not  
change my search input, but still the posts I found did not give me  
enough clue to stop me from posting here now.


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



It's usually a simple thing since there are only 3 parameters so it's  
something that you have likely mis-spelled or input in the wrong order.


It's not rocket science to figure it out, the docs are clear about how  
it works.


But a likely guess maybe that you need to connect via localhost  
instead of the full domain name.


  $db=DB::connect('mysql://metheuser:myp...@localhost/mydatabase');


Bastien

Sent from my iPod

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



Re: [PHP] What's the best way to rotate, resize, and thumbnail?

2009-01-17 Thread Ashley Sheridan
On Fri, 2009-01-16 at 20:38 -0500, Al wrote:
 
 port23user wrote:
  I have a site (done in CodeIgniter) where users can upload pictures.  When
  they upload a picture, I want to rotate it (rotating is optional, depending
  on how much cpu/ram I end up needing), resize it, and create a thumbnail. 
  Right now I'm doing it all in that order using GD, but I'm not sure if it's
  as efficient as it could be.  What's the best way to make this process
  faster?
 
 Imagick class.  Has more image manipulating functions than you'll ever use. 
 You 
 name, and there's function to do it.
 
GD is faster than ImageMagik, so if you can do it with that, keep on.
ImageMagick is only useful for the extra functionality it brings to the
table.


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] What's the best way to rotate, resize, and thumbnail?

2009-01-17 Thread Kevin Waterson
This one time, at band camp, Al n...@ridersite.org wrote:

 Imagick class.  Has more image manipulating functions than you'll ever use. 
 You 
 name, and there's function to do it.

http://www.phpro.org/examples/Create-Thumbnail-With-GD.html
http://www.phpro.org/examples/GD-Thumbnail-Based-On-Image-Type.html
http://www.phpro.org/examples/Imagick-Thumbnail-From-Center.html

but _do_ checkout imagick it has all the good toys
http://www.phpro.org/tutorials/Imagick.html

Kevin

http://phpro.org

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



Re: [PHP] What's the best way to rotate, resize, and thumbnail?

2009-01-16 Thread Al



port23user wrote:

I have a site (done in CodeIgniter) where users can upload pictures.  When
they upload a picture, I want to rotate it (rotating is optional, depending
on how much cpu/ram I end up needing), resize it, and create a thumbnail. 
Right now I'm doing it all in that order using GD, but I'm not sure if it's

as efficient as it could be.  What's the best way to make this process
faster?


Imagick class.  Has more image manipulating functions than you'll ever use. You 
name, and there's function to do it.


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



Re: [PHP] What's the best way to rotate, resize, and thumbnail?

2009-01-16 Thread mike
On Fri, Jan 16, 2009 at 5:38 PM, Al n...@ridersite.org wrote:

 Imagick class.  Has more image manipulating functions than you'll ever use.
 You name, and there's function to do it.

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

it's very cool, although it does coredump often enough to where i had
to switch back to using system(/usr/bin/convert ...) and such. it
was somewhat inconsistent so it was hard to figure out and i had no
time to try to gather any input in hopes to make the package better.

i would -love- if it would work 100% properly. i try to bypass having
to do system() calls wherever possible. this would become an
-extremely- important and useful module to have as image manipulation
is extremely common (hell i would almost suggest php change course
from gd/packaged image stuff to leveraging imagemagick fully and put
more effort on bulletproof integration!) - much like i would recommend
curl over plain old fopen and such.

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



[PHP] What's the best way to rotate, resize, and thumbnail?

2009-01-15 Thread port23user

I have a site (done in CodeIgniter) where users can upload pictures.  When
they upload a picture, I want to rotate it (rotating is optional, depending
on how much cpu/ram I end up needing), resize it, and create a thumbnail. 
Right now I'm doing it all in that order using GD, but I'm not sure if it's
as efficient as it could be.  What's the best way to make this process
faster?
-- 
View this message in context: 
http://www.nabble.com/What%27s-the-best-way-to-rotate%2C-resize%2C-and-thumbnail--tp21485027p21485027.html
Sent from the PHP - General mailing list archive at Nabble.com.


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



Re: [PHP] What's the best way to rotate, resize, and thumbnail?

2009-01-15 Thread Nitsan Bin-Nun
Umm I don't think there is any benchmark tests that will suit your case, it
really depends on what you are going to do to the image. I suggest you to
benchmark and measure these things, I also know codeigniter has a built-in
image editing class, and as far as I remember you can choose in your config
files whether to use imagemagick or GD.

HTH,
Nitsan

On Thu, Jan 15, 2009 at 9:27 PM, port23user j...@boogly.net wrote:


 I have a site (done in CodeIgniter) where users can upload pictures.  When
 they upload a picture, I want to rotate it (rotating is optional, depending
 on how much cpu/ram I end up needing), resize it, and create a thumbnail.
 Right now I'm doing it all in that order using GD, but I'm not sure if it's
 as efficient as it could be.  What's the best way to make this process
 faster?
 --
 View this message in context:
 http://www.nabble.com/What%27s-the-best-way-to-rotate%2C-resize%2C-and-thumbnail--tp21485027p21485027.html
 Sent from the PHP - General mailing list archive at Nabble.com.


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




[PHP] PHP's mail(): proper way to send a 'From' header

2008-07-07 Thread Jay Moore
Greetings folks. I seem to be having a problem with PHP's mail() 
function and sending 'From' headers properly. Here's my setup:


I have a site I set up for a client that has a form their clients can 
fill out to submit some data. When the form is submitted, I have PHP 
gather the data and create the body of an email which is then sent to 
both the owners of the site and back to the person who submitted the 
data. Because the server hosts multiple sites, I am sending an 
additional 'From' header so the email doesn't appear to come from the 
hostname of the server itself ([EMAIL PROTECTED]).


Because I did not have a DNS entry for my hostname, the 'domain does not 
exist' error I'm seeing in the bounce emails is correct. I do not wish 
to keep a DNS entry for it (I have added one as a temporary fix), as 
that doesn't fix the 'From' header issue to begin with, so I would 
appreciate it if you did not make that suggestion.


As per PHP's documentation of the mail() function, I am sending the 
header like so:


From:  [EMAIL PROTECTED]

I am getting bounce emails from certain ISPs (AOL, Roadrunner, some 
local ISPs) saying the sender's domain does not exist. It seems that 
either mails are coming from my hostname ([EMAIL PROTECTED]), or 
those ISPs are reading the additional headers incorrectly. 
Unfortunately, this is not acceptable. People aren't getting their 
emails, and the hammer is coming down on me.


As far as I know (based on the lack of bounce emails), this worked fine 
on PHP4, but with our new webserver (running PHP5), I'm experiencing 
problems. Far as I can tell, the mail() function has not changed between 
versions.


I'm stumped here and need to get this fixed asap. I've tried 'From' and 
'FROM', tried a 'Name Here [EMAIL PROTECTED]' format, and tried terminating 
with double newlines with and without the carriage return. Nothing seems 
to work. I've even gone so far as to edit php.ini with a default from 
address, but that doesn't appear to have fixed anything either.


Please help.

Thanks in advance,
Jay

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



[PHP] PHP's mail(): proper way to send a 'From' header

2008-07-07 Thread Jay Moore
**Apologies if this posts twice.  I got some crazy response from the 
server after sending this the first time.**


I have a site I set up for a client that has a form their clients can
fill out to submit some data. When the form is submitted, I have PHP
gather the data and create the body of an email which is then sent to
both the owners of the site and back to the person who submitted the
data. Because the server hosts multiple sites, I am sending an
additional 'From' header so the email doesn't appear to come from the
hostname of the server itself ([EMAIL PROTECTED]).

As per PHP's documentation of the mail() function, I am sending the
header like so:

From:  [EMAIL PROTECTED]

I am getting bounce emails from certain ISPs (AOL, Roadrunner, some
local ISPs) saying the sender's domain does not exist. It seems that
either mails are coming from my hostname ([EMAIL PROTECTED]), or 
those ISPs are reading the additional headers incorrectly. 
Unfortunately, this is not acceptable. People aren't getting their 
emails, and the hammer is coming down on me.


Because I did not have a DNS entry for my hostname, the 'domain does not
exist' error I'm seeing in the bounce emails is correct. I do not wish
to keep a DNS entry for it (I have added one as a temporary fix), as
that doesn't fix the 'From' header issue to begin with, so I would
appreciate it if you did not make that suggestion.

As far as I know (based on the lack of bounce emails), this worked fine 
on PHP4, but with our new webserver (running PHP5), I'm experiencing 
problems. Far as I can tell, the mail() function has not changed between 
versions.


I'm stumped here and need to get this fixed asap. I've tried 'From' and 
'FROM', tried a 'Name Here [EMAIL PROTECTED]' format, and tried terminating 
with double newlines with and without the carriage return. Nothing seems 
to work. I've even gone so far as to edit php.ini with a default from 
address, but that doesn't appear to have fixed anything either.


Please help.

Thanks in advance,
Jay

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



Re: [PHP] PHP's mail(): proper way to send a 'From' header

2008-07-07 Thread Dan Shirah
You missed the period in your header to join the name and the line break??

'From: [EMAIL PROTECTED]' . \r\n
On 7/7/08, Jay Moore [EMAIL PROTECTED] wrote:

 Greetings folks. I seem to be having a problem with PHP's mail() function
 and sending 'From' headers properly. Here's my setup:

 I have a site I set up for a client that has a form their clients can fill
 out to submit some data. When the form is submitted, I have PHP gather the
 data and create the body of an email which is then sent to both the owners
 of the site and back to the person who submitted the data. Because the
 server hosts multiple sites, I am sending an additional 'From' header so the
 email doesn't appear to come from the hostname of the server itself (
 [EMAIL PROTECTED]).

 Because I did not have a DNS entry for my hostname, the 'domain does not
 exist' error I'm seeing in the bounce emails is correct. I do not wish to
 keep a DNS entry for it (I have added one as a temporary fix), as that
 doesn't fix the 'From' header issue to begin with, so I would appreciate it
 if you did not make that suggestion.

 As per PHP's documentation of the mail() function, I am sending the header
 like so:

 From:  [EMAIL PROTECTED]

 I am getting bounce emails from certain ISPs (AOL, Roadrunner, some local
 ISPs) saying the sender's domain does not exist. It seems that either mails
 are coming from my hostname ([EMAIL PROTECTED]), or those ISPs are
 reading the additional headers incorrectly. Unfortunately, this is not
 acceptable. People aren't getting their emails, and the hammer is coming
 down on me.

 As far as I know (based on the lack of bounce emails), this worked fine on
 PHP4, but with our new webserver (running PHP5), I'm experiencing problems.
 Far as I can tell, the mail() function has not changed between versions.

 I'm stumped here and need to get this fixed asap. I've tried 'From' and
 'FROM', tried a 'Name Here [EMAIL PROTECTED]' format, and tried terminating
 with double newlines with and without the carriage return. Nothing seems to
 work. I've even gone so far as to edit php.ini with a default from address,
 but that doesn't appear to have fixed anything either.

 Please help.

 Thanks in advance,
 Jay

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




Re: [PHP] PHP's mail(): proper way to send a 'From' header

2008-07-07 Thread Daniel Brown
On Mon, Jul 7, 2008 at 2:06 PM, Dan Shirah [EMAIL PROTECTED] wrote:
 You missed the period in your header to join the name and the line break??

That's not required, since the OP is using double quotes
(translation will occur).

-- 
/Daniel P. Brown
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

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



Re: [PHP] PHP's mail(): proper way to send a 'From' header

2008-07-07 Thread Eric Butera
On Mon, Jul 7, 2008 at 2:06 PM, Dan Shirah [EMAIL PROTECTED] wrote:
 You missed the period in your header to join the name and the line break??

 'From: [EMAIL PROTECTED]' . \r\n
 On 7/7/08, Jay Moore [EMAIL PROTECTED] wrote:

 Greetings folks. I seem to be having a problem with PHP's mail() function
 and sending 'From' headers properly. Here's my setup:

 I have a site I set up for a client that has a form their clients can fill
 out to submit some data. When the form is submitted, I have PHP gather the
 data and create the body of an email which is then sent to both the owners
 of the site and back to the person who submitted the data. Because the
 server hosts multiple sites, I am sending an additional 'From' header so the
 email doesn't appear to come from the hostname of the server itself (
 [EMAIL PROTECTED]).

 Because I did not have a DNS entry for my hostname, the 'domain does not
 exist' error I'm seeing in the bounce emails is correct. I do not wish to
 keep a DNS entry for it (I have added one as a temporary fix), as that
 doesn't fix the 'From' header issue to begin with, so I would appreciate it
 if you did not make that suggestion.

 As per PHP's documentation of the mail() function, I am sending the header
 like so:

 From:  [EMAIL PROTECTED]

 I am getting bounce emails from certain ISPs (AOL, Roadrunner, some local
 ISPs) saying the sender's domain does not exist. It seems that either mails
 are coming from my hostname ([EMAIL PROTECTED]), or those ISPs are
 reading the additional headers incorrectly. Unfortunately, this is not
 acceptable. People aren't getting their emails, and the hammer is coming
 down on me.

 As far as I know (based on the lack of bounce emails), this worked fine on
 PHP4, but with our new webserver (running PHP5), I'm experiencing problems.
 Far as I can tell, the mail() function has not changed between versions.

 I'm stumped here and need to get this fixed asap. I've tried 'From' and
 'FROM', tried a 'Name Here [EMAIL PROTECTED]' format, and tried terminating
 with double newlines with and without the carriage return. Nothing seems to
 work. I've even gone so far as to edit php.ini with a default from address,
 but that doesn't appear to have fixed anything either.

 Please help.

 Thanks in advance,
 Jay

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




Dan,

His example would have worked since it was the entire thing surrounded
in quotes.


Jay,

Perhaps you can use the additional parameters to -f a return path
along with your header.  Whatever your current scripts domain is can
be set as the [EMAIL PROTECTED] as long as you control the
domain (see SPF rules).  Maybe this will fix your issues?

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



Re: [PHP] PHP's mail(): proper way to send a 'From' header

2008-07-07 Thread Daniel Brown
On Mon, Jul 7, 2008 at 1:50 PM, Jay Moore [EMAIL PROTECTED] wrote:
 Greetings folks. I seem to be having a problem with PHP's mail() function
 and sending 'From' headers properly. Here's my setup:

[snip!]

 I am getting bounce emails from certain ISPs (AOL, Roadrunner, some local
 ISPs) saying the sender's domain does not exist. It seems that either mails
 are coming from my hostname ([EMAIL PROTECTED]), or those ISPs are
 reading the additional headers incorrectly. Unfortunately, this is not
 acceptable. People aren't getting their emails, and the hammer is coming
 down on me.

Jay, try something like this:

?php

$to = [EMAIL PROTECTED];

$from = [EMAIL PROTECTED];

$subject = This is a test!;

$body  = \tThis is a test email.\n;
$body .= That is all.;

$headers  = From: .$from.\r\n;
$headers .= Reply-To: .$from.\r\n;
$headers .= X-Mailer: .basename(__FILE__).-PHP/.phpversion().\r\n;
$headers .= Return-Path: .$from.\r\n;

mail($to,$subject,$body,$headers,'-f'.$from);
?

Note the fifth parameter passed to mail():

http://php.net/mail

-- 
/Daniel P. Brown
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

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



Re: [PHP] PHP's mail(): proper way to send a 'From' header

2008-07-07 Thread Eric Butera
On Mon, Jul 7, 2008 at 2:13 PM, Daniel Brown [EMAIL PROTECTED] wrote:
 On Mon, Jul 7, 2008 at 1:50 PM, Jay Moore [EMAIL PROTECTED] wrote:
 Greetings folks. I seem to be having a problem with PHP's mail() function
 and sending 'From' headers properly. Here's my setup:

 [snip!]

 I am getting bounce emails from certain ISPs (AOL, Roadrunner, some local
 ISPs) saying the sender's domain does not exist. It seems that either mails
 are coming from my hostname ([EMAIL PROTECTED]), or those ISPs are
 reading the additional headers incorrectly. Unfortunately, this is not
 acceptable. People aren't getting their emails, and the hammer is coming
 down on me.

Jay, try something like this:

 ?php

 $to = [EMAIL PROTECTED];

 $from = [EMAIL PROTECTED];

 $subject = This is a test!;

 $body  = \tThis is a test email.\n;
 $body .= That is all.;

 $headers  = From: .$from.\r\n;
 $headers .= Reply-To: .$from.\r\n;
 $headers .= X-Mailer: .basename(__FILE__).-PHP/.phpversion().\r\n;
 $headers .= Return-Path: .$from.\r\n;

 mail($to,$subject,$body,$headers,'-f'.$from);
 ?

Note the fifth parameter passed to mail():

http://php.net/mail

 --
 /Daniel P. Brown
 Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
 $59.99/mo. with no contract!
 Dedicated servers, VPS, and hosting from $2.50/mo.

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



Yep!  Just a note on this though.  You have to control the domain
you're forcing the return-path on or else it will get rejected by a
lot of servers because of SPF rules.  It has bit my company in the
behind quite a bit recently.  :)

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



Re: [PHP] PHP's mail(): proper way to send a 'From' header

2008-07-07 Thread Daniel Brown
On Mon, Jul 7, 2008 at 2:17 PM, Eric Butera [EMAIL PROTECTED] wrote:

 Yep!  Just a note on this though.  You have to control the domain
 you're forcing the return-path on or else it will get rejected by a
 lot of servers because of SPF rules.  It has bit my company in the
 behind quite a bit recently.  :)

Thanks for adding that, Eric.  I had forgotten to mention it.  :-)

And I've run into the same problems, especially in the last year
or so.  It was because of an inter-domain contact form, similar to
email, that allowed users to mail each other online without giving out
an actual email address.  The forced FROM caused a lot of problems,
which could only be fixed by making permanent changes to the DNS ---
which the OP doesn't want to do in this case.

-- 
/Daniel P. Brown
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

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



Re: [PHP] PHP's mail(): proper way to send a 'From' header

2008-07-07 Thread Stut

On 7 Jul 2008, at 18:50, Jay Moore wrote:
Greetings folks. I seem to be having a problem with PHP's mail()  
function and sending 'From' headers properly. Here's my setup:


I have a site I set up for a client that has a form their clients  
can fill out to submit some data. When the form is submitted, I have  
PHP gather the data and create the body of an email which is then  
sent to both the owners of the site and back to the person who  
submitted the data. Because the server hosts multiple sites, I am  
sending an additional 'From' header so the email doesn't appear to  
come from the hostname of the server itself ([EMAIL PROTECTED]).


Because I did not have a DNS entry for my hostname, the 'domain does  
not exist' error I'm seeing in the bounce emails is correct. I do  
not wish to keep a DNS entry for it (I have added one as a temporary  
fix), as that doesn't fix the 'From' header issue to begin with, so  
I would appreciate it if you did not make that suggestion.


As per PHP's documentation of the mail() function, I am sending the  
header like so:


From:  [EMAIL PROTECTED]

I am getting bounce emails from certain ISPs (AOL, Roadrunner, some  
local ISPs) saying the sender's domain does not exist. It seems that  
either mails are coming from my hostname ([EMAIL PROTECTED]), or  
those ISPs are reading the additional headers incorrectly.  
Unfortunately, this is not acceptable. People aren't getting their  
emails, and the hammer is coming down on me.


As far as I know (based on the lack of bounce emails), this worked  
fine on PHP4, but with our new webserver (running PHP5), I'm  
experiencing problems. Far as I can tell, the mail() function has  
not changed between versions.


I'm stumped here and need to get this fixed asap. I've tried 'From'  
and 'FROM', tried a 'Name Here [EMAIL PROTECTED]' format, and tried  
terminating with double newlines with and without the carriage  
return. Nothing seems to work. I've even gone so far as to edit  
php.ini with a default from address, but that doesn't appear to have  
fixed anything either.


The ISPs are likely looking at the envelope sender rather than the  
sender specified in the headers.


If you're on a box using sendmail (which I think you are based on what  
you've said) you can set this using the 5th parameter to mail set to - 
f followed by the email address you want to use.


i.e. '[EMAIL PROTECTED]'

I believe this is covered on the manual page for the mail function.

-Stut

--
http://stut.net/

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



Re: [PHP] PHP's mail(): proper way to send a 'From' header

2008-07-07 Thread Chris

 ?php
 
 $to = [EMAIL PROTECTED];
 
 $from = [EMAIL PROTECTED];
 
 $subject = This is a test!;
 
 $body  = \tThis is a test email.\n;
 $body .= That is all.;
 
 $headers  = From: .$from.\r\n;
 $headers .= Reply-To: .$from.\r\n;
 $headers .= X-Mailer: .basename(__FILE__).-PHP/.phpversion().\r\n;
 $headers .= Return-Path: .$from.\r\n;
 
 mail($to,$subject,$body,$headers,'-f'.$from);
 ?
 
 Note the fifth parameter passed to mail():
 
 http://php.net/mail
 

And also note that the 5th parameter is an email address only.. Don't do
something like:

?php

$from = Me [EMAIL PROTECTED];

and try to use that as the 5th parameter, it won't work.

-- 
Postgresql  php tutorials
http://www.designmagick.com/

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



RES: [PHP] Newbie question, Which way is best?

2008-03-20 Thread Thiago Pojda
De: George J [mailto:[EMAIL PROTECTED] 

 So calling the script via the form works i.e it passes the 
 neccessary variables to constrct the sql query for the next 
 call. 

As Shawn said, if you really need the query again add it to session, never,
NEVER give the user the ability to see/execute queries by himself (remember
POST data could be easily manipulated). Remember what Daniel said, adding a
DELETE FROM is not hard and veeery bad.

 If the user clicks one of the pagination links, that 
 calls itself, all that is passed is the page=$i variable. I 
 need to include the 'SELECT * FROM...' query either as a string 
 or an array of seperate values for the changed query.

Ok, let me ask you something. Why post to itself? You could have a script
only to do form actions, that way you can:
1 Separate huge php validations with your html form.
2 Use functions to handle the incoming data and writing the new query (or
the old one again).

As it's built at server side, the user is never going to see your query or
[1]manipulate it as you're writing it all over again, just using your old
parameters (they could be added as hidden fields in the form if strictly
necessary).


 So, as I see it, the pagination links won't POST the form 
 variables. How do I pass the 'SELECT * FROM mytable WHERE 
 selection=option LIMIT start, range' 
 query to the called script?

You should try building a default query where you only add the parameters
given by the user. If you can't seem to recover that, add them to $_SESSION
and you'll be fine next time you want them (if you don't overwrite it =] ).

 George
Welcome and keep asking :)


[1] As long as you treat the user input properly, as other said.
 



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



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



Re: [PHP] Newbie question, Which way is best?

2008-03-20 Thread Philip Thompson

On Mar 19, 2008, at 5:13 PM, George J wrote:

Hi Jason,

Hope this helps -
my 'display_products.php' script
--
form method='post' action='display_products.php'
...
input type='hidden' name= 'query' value=$query
input type='submit' Value='Go'/td
...
// pagination routine
conditional code...
}else{
  echo(a href=\display_products.php?page=$i\img src=$st border= 
\0\

/a );

  }
---

So calling the script via the form works i.e it passes the neccessary
variables to constrct the sql query for the next call. If the user  
clicks
one of the pagination links, that calls itself, all that is passed  
is the
page=$i variable. I need to include the 'SELECT * FROM...' query  
either as a

string or an array of seperate values for the changed query.

So, as I see it, the pagination links won't POST the form variables.  
How do
I pass the 'SELECT * FROM mytable WHERE selection=option LIMIT  
start, range'

query
to the called script?

George


I don't know if anyone has answered the question you have asked at  
least twice... How do I pass the query to the next page? Here's how  
I would approach it. Don't pass the query - all you need is the page  
number. This code hasn't been tested, but I think you'll get the idea.


?php
// thispage.php
if (isset ($_POST['submitted'])) {
$resultsPerPage = 50; // or whatever value
$page = mysql_real_escape_string ($_POST['page']);

$start = ($page * $resultsPerPage) - $resultsPerPage;
$length = $start + $resultsPerPage;

// Notice how you don't send the query in the POST or GET, just  
the page number
$sql = SELECT `field` FROM `table` WHERE (`field_a` =  
'someValue') LIMIT $start, $length;

$results = mysql_query ($sql);
}

// Go to next page
$page = $_POST['page'] ? (int) $_POST['page'] + 1 : 1;
?
...
form method=post action=thispage.php
input type=submit value=Go /
input type=hidden name=page value=?php echo htmlentities  
($page); ? /

input type=hidden name=submitted value=1 /
/form
...

?php
while ($row = mysql_fetch_array ($results, MYSQL_ASSOC)) {
// Display results
}
?


Hopefully that helps a little bit.

~Philip

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



Re: [PHP] Newbie question, Which way is best?

2008-03-20 Thread George J

Thiago Pojda [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 De: George J [mailto:[EMAIL PROTECTED]

 So calling the script via the form works i.e it passes the
 neccessary variables to constrct the sql query for the next
 call.

 As Shawn said, if you really need the query again add it to session, 
 never,
 NEVER give the user the ability to see/execute queries by himself 
 (remember
 POST data could be easily manipulated). Remember what Daniel said, adding 
 a
 DELETE FROM is not hard and veeery bad
OK. I see the logic.

 Ok, let me ask you something. Why post to itself? You could have a script
 only to do form actions, that way you can:
 1 Separate huge php validations with your html form.
 2 Use functions to handle the incoming data and writing the new query (or
 the old one again).

I suspect that most folk in my position start the learning process by 
finding a script that does a similar task and adapting it. This is basically 
what I've done. I started by finding a form example and then added a 
pagination routine then... Several deadends later... Not the best way to 
write anything but the simplest of scripts. However, the numerous changes to 
the code has entailed lots of learning during the process. So in answer to 
your question. I didn't set out with any idea of the best way to write the 
script. Just a broad idea of what I wanted to end up with.

 As it's built at server side, the user is never going to see your query or
 [1]manipulate it as you're writing it all over again, just using your old
 parameters (they could be added as hidden fields in the form if strictly
 necessary).


 So, as I see it, the pagination links won't POST the form
 variables. How do I pass the 'SELECT * FROM mytable WHERE
 selection=option LIMIT start, range'
 query to the called script?

 You should try building a default query where you only add the parameters
 given by the user. If you can't seem to recover that, add them to 
 $_SESSION
 and you'll be fine next time you want them (if you don't overwrite it 
 =] ).

My query code-

---SQL query construction block
  $query = SELECT * FROM prods ;
  if($catagory != 0){   // 
if category != 0
 $where=WHERE c = $catagory ;
 if ($manu != 0){  // check 
manu != 0
$and = AND m = $manu ;
if ($searchstring != 0){
   $and = $and.AND description LIKE \%$searchstring%\ ; // 
check like != 0
}
 }else{
...
$query=$query.$where.$and.$like

---
Can you please explain your suggestion above in laymans terms. I can't see 
what you have in mind. Is it your suggestion to use one script, containing a 
from, that calls another script that handles my query construction? That far 
I follow you but what happens next?




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



Re: [PHP] Newbie question, Which way is best?

2008-03-20 Thread Shawn McKenzie
George J wrote:
 Thiago Pojda [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 De: George J [mailto:[EMAIL PROTECTED]

 So calling the script via the form works i.e it passes the
 neccessary variables to constrct the sql query for the next
 call.
 As Shawn said, if you really need the query again add it to session, 
 never,
 NEVER give the user the ability to see/execute queries by himself 
 (remember
 POST data could be easily manipulated). Remember what Daniel said, adding 
 a
 DELETE FROM is not hard and veeery bad
 OK. I see the logic.
 
 Ok, let me ask you something. Why post to itself? You could have a script
 only to do form actions, that way you can:
 1 Separate huge php validations with your html form.
 2 Use functions to handle the incoming data and writing the new query (or
 the old one again).
 
 I suspect that most folk in my position start the learning process by 
 finding a script that does a similar task and adapting it. This is basically 
 what I've done. I started by finding a form example and then added a 
 pagination routine then... Several deadends later... Not the best way to 
 write anything but the simplest of scripts. However, the numerous changes to 
 the code has entailed lots of learning during the process. So in answer to 
 your question. I didn't set out with any idea of the best way to write the 
 script. Just a broad idea of what I wanted to end up with.
 
 As it's built at server side, the user is never going to see your query or
 [1]manipulate it as you're writing it all over again, just using your old
 parameters (they could be added as hidden fields in the form if strictly
 necessary).


 So, as I see it, the pagination links won't POST the form
 variables. How do I pass the 'SELECT * FROM mytable WHERE
 selection=option LIMIT start, range'
 query to the called script?
 You should try building a default query where you only add the parameters
 given by the user. If you can't seem to recover that, add them to 
 $_SESSION
 and you'll be fine next time you want them (if you don't overwrite it 
 =] ).

 My query code-
 
 ---SQL query construction block
   $query = SELECT * FROM prods ;
   if($catagory != 0){   // 
 if category != 0
  $where=WHERE c = $catagory ;
  if ($manu != 0){  // check 
 manu != 0
 $and = AND m = $manu ;
 if ($searchstring != 0){
$and = $and.AND description LIKE \%$searchstring%\ ; // 
 check like != 0
 }
  }else{
 ...
 $query=$query.$where.$and.$like
 
 ---
 Can you please explain your suggestion above in laymans terms. I can't see 
 what you have in mind. Is it your suggestion to use one script, containing a 
 from, that calls another script that handles my query construction? That far 
 I follow you but what happens next?
 
 
 
What file is this?  is the pagination code in this file also?  If not
where?  Post you pagination code and this is a simple explanation.

Build your query as you've done and stick it in a session var.  It is
now available to future calls to this page or other pages.

-Shawn

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



Re: [PHP] Newbie question, Which way is best?

2008-03-20 Thread George J
Hi Shawn,

 My query code-

 ---SQL query construction block
   $query = SELECT * FROM prods ;
   if($catagory != 0){ 
 //
 if category != 0
  $where=WHERE c = $catagory ;
  if ($manu != 0){  // 
 check
 manu != 0
 $and = AND m = $manu ;
 if ($searchstring != 0){
$and = $and.AND description LIKE \%$searchstring%\ ; 
 //
 check like != 0
 }
  }else{
 ...
 $query=$query.$where.$and.$like

 ---
 Can you please explain your suggestion above in laymans terms. I can't 
 see
 what you have in mind. Is it your suggestion to use one script, 
 containing a
 from, that calls another script that handles my query construction? That 
 far
 I follow you but what happens next?



 What file is this?  is the pagination code in this file also?  If not
 where?  Post you pagination code and this is a simple explanation.

 Build your query as you've done and stick it in a session var.  It is
 now available to future calls to this page or other pages.

 -Shawn

The above code was included in post to show how query is constructed.

Heres my pagination code.
---
if($page  1){ // if number of pages  1 then display 'Previous' button
$pageprev = $page-1;
   echo(a href=\display_products.php?page=$pageprev\img 
src=\btnprevenabled.gif\ ALT=\Previous\ border=\0\ /a );
}else{
echo(img src=\btnprevdisnabled.gif\ ALT=\Previous\border=\0\ 
  );
}
//
$numpages = $totalrows / $show; //$show holds number of items to display per 
page
// display a button for each page with current page showing disabled button
for($i = 1; $i = $numpages; $i++){
   $str1=btn_;
   $str2=$i;
if($i == $page){
 $str3=$str1.$str2.disabled.gif;
  echo(img src=$str3 border=\0\ );
}else{
 $str3=$str1.$str2._enabled.gif;
echo(a href=\displayproducts.php?page=$i\img src=$str3 
border=\0\ /a );
 }
}
// if last page is less than full
if(($totalrows % $show) != 0){
   $str2=$i;
  if($i == $page){
 $str3=$str1.$str2.disabled.gif;
  echo(img src=$str3 border=\0\ );//$i );
}else{
 $str3=$str1.$str2.enabled.gif;
  echo(a href=\displayproducts.php?page=$i\img src=$str3 
border=\0\ /a );//$i/a );
}
}
// Display the enabled or disabled 'Next' button
if(($totalrows - ($show * $page))  0){
  //$str3=$str1.$str2.disabled.gif;
$pagenext =$page+1;
echo(a href=\displayproducts.php?page=$pagenext\img 
src=\btnnextenabled.gif\ border=\0\ /a);//$i/a );
}else{
   $pagenext =$page+1;
echo(img src=\btnnextdisabled.gif\ ALT=\Next\border=\0\  
);
}
?
/td/font/tr/table
---

Thanks for sticking with me.

George



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



Re: [PHP] Newbie question, Which way is best?

2008-03-20 Thread Philip Thompson

On Mar 20, 2008, at 12:05 PM, George Jamieson wrote:


Hi Philip,

Hope you don't mind me sending this to you direct. Thanks for the  
answer

but... I'm sorry I don't follow you.

My form sets up the query parameters. It works.

My pagination code passes the page no. It works.

What it doesn't do is provide the next execution of my script with the
query. I pass the page no. but how do I either use the same query  
but with
new LIMIT parameters or reconstruct the entire query with the new  
LIMIT.


My form gives the user options to search by manufacturer, gategory  
or search
string. sorted by description, finish or price. I've just added a  
drop down

box for number of items to be displayed at a time.

I want to use my pagination script to scroll, page by page, through  
the
resultset. So if I call my script again, with the new page number, I  
have no
way of reusing the same query as the user is not required to rePOST  
the form

with its parameters.

I can't see how your code allows me to do that.


Because I increment the page count ($page) each time... So, each time  
you hit Go, then it finds the next page. Of course, this is not really  
made for production - you would want to find a more user-friendly way  
to accomplish showing a result set.


You could change it up to use _GET instead:

a href=thispage.php?page=3Go to Page 3/a

Then modify your PHP code to accept _GET values along with/instead of  
_POST values:


?php
if (isset ($_POST['submitted']) || !empty ($_GET['page'])) {
$page = $_POST['page'] ? (int) $_POST['page'] : (int)  
$_GET['page'];

...
}
?

I feel like we've explained this fairly well, but you may not  
completely understand. Let us know if we need to break it down a  
little bit more. We would be happy to point you to some materials that  
can assist you.


~Philip



Regards
George


to the called script?


George


I don't know if anyone has answered the question you have asked at
least twice... How do I pass the query to the next page? Here's how
I would approach it. Don't pass the query - all you need is the page
number. This code hasn't been tested, but I think you'll get the  
idea.


?php
// thispage.php
if (isset ($_POST['submitted'])) {
$resultsPerPage = 50; // or whatever value
$page = mysql_real_escape_string ($_POST['page']);

$start = ($page * $resultsPerPage) - $resultsPerPage;
$length = $start + $resultsPerPage;

// Notice how you don't send the query in the POST or GET, just
the page number
$sql = SELECT `field` FROM `table` WHERE (`field_a` =
'someValue') LIMIT $start, $length;
$results = mysql_query ($sql);
}

// Go to next page
$page = $_POST['page'] ? (int) $_POST['page'] + 1 : 1;
?
...
form method=post action=thispage.php
input type=submit value=Go /
input type=hidden name=page value=?php echo htmlentities
($page); ? /
input type=hidden name=submitted value=1 /
/form
...

?php
while ($row = mysql_fetch_array ($results, MYSQL_ASSOC)) {
// Display results
}
?


Hopefully that helps a little bit.

~Philip


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



[PHP] Newbie question, Which way is best?

2008-03-19 Thread George J
Hi,

I have a script that contains a form and a pagination routine that calls 
itself. I want to pass an sql query along with some other variables to the 
called script. The code to acheive this, using the form, is working but when 
I try to write the code, using the scripts URL to call itself, I am having 
problems successfully passing the SQL query string within the url.

The form is used to construct a string containing a sql query. Whereas when 
the pagination calls the script all it does is changes the LIMIT part of the 
sql query. I know it won't pass the original query unless I add it to the 
URL address.

Is there a 'proper' way to write this code? Should I add the query to the 
URL or is there a better way?

TIA
George 



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



Re: [PHP] Newbie question, Which way is best?

2008-03-19 Thread Daniel Brown
On Wed, Mar 19, 2008 at 3:47 PM, George J [EMAIL PROTECTED] wrote:
 Hi,

  I have a script that contains a form and a pagination routine that calls
  itself. I want to pass an sql query along with some other variables to the
  called script. The code to acheive this, using the form, is working but when
  I try to write the code, using the scripts URL to call itself, I am having
  problems successfully passing the SQL query string within the url.

WHOA!  Passing the SQL query via a URL is a Very Bad Idea[tm]!

Show some code so that we can all see more about what you're
trying to do.  Maybe I'm misunderstanding your question.

-- 
/Daniel P. Brown
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283

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



Re: [PHP] Newbie question, Which way is best?

2008-03-19 Thread Andrew Ballard
On Wed, Mar 19, 2008 at 3:47 PM, George J [EMAIL PROTECTED] wrote:
 Hi,

  I have a script that contains a form and a pagination routine that calls
  itself. I want to pass an sql query along with some other variables to the
  called script. The code to acheive this, using the form, is working but when
  I try to write the code, using the scripts URL to call itself, I am having
  problems successfully passing the SQL query string within the url.

  The form is used to construct a string containing a sql query. Whereas when
  the pagination calls the script all it does is changes the LIMIT part of the
  sql query. I know it won't pass the original query unless I add it to the
  URL address.

  Is there a 'proper' way to write this code? Should I add the query to the
  URL or is there a better way?

  TIA
  George

My personal preference is to add all of the query parameters as hidden
fields in your form and pass them along from page to page. I wouldn't
send the actual SQL query (or any part of it) as part of the URL.

Andrew

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



Re: [PHP] Newbie question, Which way is best?

2008-03-19 Thread George J
Hi Daniel,

WHOA!  Passing the SQL query via a URL is a Very Bad Idea[tm]!

As a newbie I just have to ask why. I suspect you're going to say it gives 
the table and field names used in my database. I'm not really aware of all 
the possible avenues that this method might open up. It just feels wrong to 
include these details. This is the reason I've asked for help.

The form part of the script works fine so can we ignore that or does it 
impact on the pagination code that I'm having trouble with.

When the form calls the script it passes all the parameters that the script 
uses to construct a SELECT query. This works fine.

When the pagination calls the script it passes a new page number. This works 
fine but is where my limited experience lets me down. I need to pass the 
SELECT query, as is, back to the same script with a way to change just the 
LIMIT part of the query. Changing the LIMIT parameters simple lets me 
display another page of the returned query. I can do this change prior to 
call but what options have I on including the query in my call. Could I 
camouflage the query parameters in an array for example?

George








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



Re: [PHP] Newbie question, Which way is best?

2008-03-19 Thread Daniel Brown
On Wed, Mar 19, 2008 at 4:45 PM, George J [EMAIL PROTECTED] wrote:
 Hi Daniel,


  WHOA!  Passing the SQL query via a URL is a Very Bad Idea[tm]!

  As a newbie I just have to ask why. I suspect you're going to say it gives
  the table and field names used in my database. I'm not really aware of all
  the possible avenues that this method might open up. It just feels wrong to
  include these details. This is the reason I've asked for help.

That's exactly what you should be doing, George.  That's how you learn!  ;-)

Not only are you giving away the schema of your database, but it
makes it that much easier to do VERY nasty things.  For example, say
you access the file like so:


http://www.domain.com/path/script.php?query=SELECT%20*%20FROM%20table%20WHERE%20result='this'%20LIMIT%2020,%2030

I could change it to something like this:


http://www.domain.com/path/script.php?query=SELECT%20*%20FROM%20table%20WHERE%20result='this'%20LIMIT%2020,%2030;DELETE%20FROM%20TABLE%20WHERE%201

And your database table is gone.

  The form part of the script works fine so can we ignore that or does it
  impact on the pagination code that I'm having trouble with.

As long as you sanitize anything sent to the database, I'm sure
it's fine.  Check out mysql_real_escape_string() for more on that:
http://php.net/mysql-real-escape-string

NOTE: If you're using mysqli, you don't need to add
mysql_real_escape_string() because it's already handled automatically.

-- 
/Daniel P. Brown
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283

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



Re: [PHP] Newbie question, Which way is best?

2008-03-19 Thread Jason Pruim


On Mar 19, 2008, at 4:45 PM, George J wrote:


Hi Daniel,


  WHOA!  Passing the SQL query via a URL is a Very Bad Idea[tm]!


As a newbie I just have to ask why. I suspect you're going to say it  
gives
the table and field names used in my database. I'm not really aware  
of all
the possible avenues that this method might open up. It just feels  
wrong to

include these details. This is the reason I've asked for help.

The form part of the script works fine so can we ignore that or does  
it

impact on the pagination code that I'm having trouble with.

When the form calls the script it passes all the parameters that the  
script

uses to construct a SELECT query. This works fine.

When the pagination calls the script it passes a new page number.  
This works
fine but is where my limited experience lets me down. I need to pass  
the
SELECT query, as is, back to the same script with a way to change  
just the

LIMIT part of the query. Changing the LIMIT parameters simple lets me
display another page of the returned query. I can do this change  
prior to
call but what options have I on including the query in my call.  
Could I

camouflage the query parameters in an array for example?



Hi George,

As a relative newbie my self I think I understand what you are trying  
to do.


The reason Dan asked for the code though is because when you show the  
code we can easily point out what/where the issue is. If potental  
attackers have access to your field names they can much easier try and  
insert stuff into your database.


What I would probably do though is something along the lines of this:

//Always escape your data to make it a little harder on the hackers
$par1 = mysql_real_escape($_POST['parameter1']);
$par2 = mysql_real_escape($_POST['parameter2']);

$sql = SELECT * from tablename where parameter1=.$par1. AND  
parameter2=.$par2: etc etc etc...


There is more to this, but this should get you started.

that way you can run the script calling the variables which were  
POSTed instead of GETed so they won't be passed in the URL. It also  
has the benefit of not revealing your field names.


Now all of that was typed from memory so please do check to make sure  
it makes sense why it's working.


JP

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



[Fwd: Re: [PHP] Newbie question, Which way is best?]

2008-03-19 Thread Shawn McKenzie
George J wrote:
 Hi Daniel,
 
WHOA!  Passing the SQL query via a URL is a Very Bad Idea[tm]!
 
 As a newbie I just have to ask why. I suspect you're going to say it gives 
 the table and field names used in my database. I'm not really aware of all 
 the possible avenues that this method might open up. It just feels wrong to 
 include these details. This is the reason I've asked for help.
 
 The form part of the script works fine so can we ignore that or does it 
 impact on the pagination code that I'm having trouble with.
 
 When the form calls the script it passes all the parameters that the script 
 uses to construct a SELECT query. This works fine.
 
 When the pagination calls the script it passes a new page number. This works 
 fine but is where my limited experience lets me down. I need to pass the 
 SELECT query, as is, back to the same script with a way to change just the 
 LIMIT part of the query. Changing the LIMIT parameters simple lets me 
 display another page of the returned query. I can do this change prior to 
 call but what options have I on including the query in my call. Could I 
 camouflage the query parameters in an array for example?
 
 George
 
 
 
 
 
 
 

Maybe add your query as a session var.  Depends upon how your app works.
 Is the pagination a series of links with get vars?

// your script that receives post data
session_start();

if(!empty($_POST)) {
$query = Build query from post vars;
$_SESSION['query'] = $query;
} else {
$query = $_SESSION['query'];
}
//  use your query

Then there's the pagination stuff, but we'd need to see how you do it.

-Shawn






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



Re: Re: [PHP] Newbie question, Which way is best?]

2008-03-19 Thread George J
Hi Shawn,

Shawn McKenzie [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 George J wrote:
 Hi Daniel,

WHOA!  Passing the SQL query via a URL is a Very Bad Idea[tm]!

 As a newbie I just have to ask why. I suspect you're going to say it 
 gives
 the table and field names used in my database. I'm not really aware of 
 all
 the possible avenues that this method might open up. It just feels wrong 
 to
 include these details. This is the reason I've asked for help.

 The form part of the script works fine so can we ignore that or does it
 impact on the pagination code that I'm having trouble with.

 When the form calls the script it passes all the parameters that the 
 script
 uses to construct a SELECT query. This works fine.

 When the pagination calls the script it passes a new page number. This 
 works
 fine but is where my limited experience lets me down. I need to pass the
 SELECT query, as is, back to the same script with a way to change just 
 the
 LIMIT part of the query. Changing the LIMIT parameters simple lets me
 display another page of the returned query. I can do this change prior to
 call but what options have I on including the query in my call. Could I
 camouflage the query parameters in an array for example?

 George



 Maybe add your query as a session var.  Depends upon how your app works.
 Is the pagination a series of links with get vars?

 // your script that receives post data
 session_start();

 if(!empty($_POST)) {
 $query = Build query from post vars;
 $_SESSION['query'] = $query;
 } else {
 $query = $_SESSION['query'];
 }
 //  use your query

 Then there's the pagination stuff, but we'd need to see how you do it.

 -Shawn

My code checks the POSTed values
---
 if (isset($_REQUEST['selected_manu'])){
 $find_manu=$_POST['selected_manu'];
---

Yes, my pagination routine uses a series of links.

I'll underlline that I'm not only learning php but also HTML. I'm trying to 
keep things simple as there is so much to learn. I'm starting from scratch 
and find the coding fairly straightforward. However, selecting the 
appropriate techniques is another matter.

George 



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



[PHP] Looking for easier way to build email message

2008-01-24 Thread Rene Brehmer
Drew a blank off the archive, so here goes...

I'm working on some forms for our company website, all of which simply have
to be mailed to us by email.

After verifying that the content of all the fields is valid and the proper
type, it builds the email message as following. This all works great, but I
want a simpler/easier way to reuse the code (we have 3 forms, with
distinctively different content, but the mail process remains the same), so
something that will do the below, but can be reduced to something like
grabbing a text file and fill in the blanks would be nice, instead of this:

  // prepare message
  if(! $error) {
$message = Information submitted with Tee Time booking form:\r\n;
$message .= Name and address:\r\n\r\n;
$message .= $name\r\n;
$message .= $address\r\n;
$message .= $city\r\n;
$message .= $state $postcode\r\n\r\n;
$message .= Email: $email\r\n;
$message .= Phone: $phone\r\n;
$message .= \r\n\r\nBooking info:\r\n\r\n;
$message .= Arrival: $a_month $a_day\r\n;
$message .= Departure: $d_month $d_day\r\n;
$message .= Persons: $persons\r\n;
$message .= Rooms: $rooms\r\n;
$message .= \r\nGolf Courses\r\n\r\n;
for($i = 1; $i  8; $i++) {
  if($_POST['course_'.$i] != 0) {
$message .= 'Course: '.$_POST['course_'.$i].\r\n;
$message .= 'Date: '.$_POST['month_'.$i].'
'.$_POST['day_'.$i].\r\n;
$message .= 'Time: '.$_POST['teetime_'.$i].\r\n;
$message .= '# of golfers: '.$_POST['golfers_'.$i].\r\n;
  }
}
if(! empty($comments)) {
  $message .= \r\nComments:\r\n$comments\r\n;
}
$message .= \r\nUser Client Info:\r\n;
$message .= 'User IP: '.$_SERVER['REMOTE_ADDR'].\r\nUser agent:
.$_SERVER['HTTP_USER_AGENT'].\r\n\r\n;


// NOTE: This code only builds the actual message, the headers are built
elsewhere in the code.
// This is our golf-package quote request (I work for a hotel) form, where
you can book up to 7 tee times. Thus the iteration in the middle, to run
through the 7 tee time fields.

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



Re: [PHP] Looking for easier way to build email message

2008-01-24 Thread Nathan Nobbe
On Jan 24, 2008 6:20 PM, Rene Brehmer [EMAIL PROTECTED] wrote:

 Drew a blank off the archive, so here goes...

 I'm working on some forms for our company website, all of which simply
 have
 to be mailed to us by email.

 After verifying that the content of all the fields is valid and the proper
 type, it builds the email message as following. This all works great, but
 I
 want a simpler/easier way to reuse the code (we have 3 forms, with
 distinctively different content, but the mail process remains the same),
 so
 something that will do the below, but can be reduced to something like
 grabbing a text file and fill in the blanks would be nice, instead of
 this:

  // prepare message
  if(! $error) {
$message = Information submitted with Tee Time booking form:\r\n;
$message .= Name and address:\r\n\r\n;
$message .= $name\r\n;
$message .= $address\r\n;
$message .= $city\r\n;
$message .= $state $postcode\r\n\r\n;
$message .= Email: $email\r\n;
$message .= Phone: $phone\r\n;
$message .= \r\n\r\nBooking info:\r\n\r\n;
$message .= Arrival: $a_month $a_day\r\n;
$message .= Departure: $d_month $d_day\r\n;
$message .= Persons: $persons\r\n;
$message .= Rooms: $rooms\r\n;
$message .= \r\nGolf Courses\r\n\r\n;
for($i = 1; $i  8; $i++) {
  if($_POST['course_'.$i] != 0) {
$message .= 'Course: '.$_POST['course_'.$i].\r\n;
$message .= 'Date: '.$_POST['month_'.$i].'
 '.$_POST['day_'.$i].\r\n;
$message .= 'Time: '.$_POST['teetime_'.$i].\r\n;
$message .= '# of golfers: '.$_POST['golfers_'.$i].\r\n;
  }
}
if(! empty($comments)) {
  $message .= \r\nComments:\r\n$comments\r\n;
}
$message .= \r\nUser Client Info:\r\n;
$message .= 'User IP: '.$_SERVER['REMOTE_ADDR'].\r\nUser agent:
 .$_SERVER['HTTP_USER_AGENT'].\r\n\r\n;


 // NOTE: This code only builds the actual message, the headers are built
 elsewhere in the code.
 // This is our golf-package quote request (I work for a hotel) form, where
 you can book up to 7 tee times. Thus the iteration in the middle, to run
 through the 7 tee time fields.


check the  archives for smtp vs. mail(); somebody mentioned a number of
classes available at this site:
http://www.phpclasses.org

some of them looked quite useful.

-nathan


Re: [PHP] Looking for easier way to build email message

2008-01-24 Thread Richard Lynch
On Thu, January 24, 2008 5:20 pm, Rene Brehmer wrote:
 Drew a blank off the archive, so here goes...

 I'm working on some forms for our company website, all of which simply
 have
 to be mailed to us by email.

 After verifying that the content of all the fields is valid and the
 proper
 type, it builds the email message as following. This all works great,
 but I
 want a simpler/easier way to reuse the code (we have 3 forms, with
 distinctively different content, but the mail process remains the
 same), so
 something that will do the below, but can be reduced to something like
 grabbing a text file and fill in the blanks would be nice, instead of
 this:

http://php.net/faq.php

foreach($_POST as $field = $value){
  $message .= $field: ;
  if (is_array($value)){
$message .= \r\n;
foreach ($value as $f = $v){
  $message .= strrepeat( , strlen($field) + 2) . $f: $v\r\n;
}
  }
  else $message .= $value\r\n;
}

And get rid of your course_1, course_2, course_3... names and use:
name=course[1], name=course[2], name=course[3]
instead.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Looking for easier way to build email message

2008-01-24 Thread Jochem Maas

a well known easy to use wrapper is phpmailer (STW), alternatively
check out Manuel Lemos' mail related offerings at phpclasses.org (his code
is, afaict, better but also a little more involved.

Rene Brehmer schreef:

Drew a blank off the archive, so here goes...

I'm working on some forms for our company website, all of which simply have
to be mailed to us by email.

After verifying that the content of all the fields is valid and the proper
type, it builds the email message as following. This all works great, but I
want a simpler/easier way to reuse the code (we have 3 forms, with
distinctively different content, but the mail process remains the same), so
something that will do the below, but can be reduced to something like
grabbing a text file and fill in the blanks would be nice, instead of this:

  // prepare message
  if(! $error) {
$message = Information submitted with Tee Time booking form:\r\n;
$message .= Name and address:\r\n\r\n;
$message .= $name\r\n;
$message .= $address\r\n;
$message .= $city\r\n;
$message .= $state $postcode\r\n\r\n;
$message .= Email: $email\r\n;
$message .= Phone: $phone\r\n;
$message .= \r\n\r\nBooking info:\r\n\r\n;
$message .= Arrival: $a_month $a_day\r\n;
$message .= Departure: $d_month $d_day\r\n;
$message .= Persons: $persons\r\n;
$message .= Rooms: $rooms\r\n;
$message .= \r\nGolf Courses\r\n\r\n;
for($i = 1; $i  8; $i++) {
  if($_POST['course_'.$i] != 0) {
$message .= 'Course: '.$_POST['course_'.$i].\r\n;
$message .= 'Date: '.$_POST['month_'.$i].'
'.$_POST['day_'.$i].\r\n;
$message .= 'Time: '.$_POST['teetime_'.$i].\r\n;
$message .= '# of golfers: '.$_POST['golfers_'.$i].\r\n;
  }
}
if(! empty($comments)) {
  $message .= \r\nComments:\r\n$comments\r\n;
}
$message .= \r\nUser Client Info:\r\n;
$message .= 'User IP: '.$_SERVER['REMOTE_ADDR'].\r\nUser agent:
.$_SERVER['HTTP_USER_AGENT'].\r\n\r\n;


// NOTE: This code only builds the actual message, the headers are built
elsewhere in the code.
// This is our golf-package quote request (I work for a hotel) form, where
you can book up to 7 tee times. Thus the iteration in the middle, to run
through the 7 tee time fields.



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



Re: [PHP] Looking for easier way to build email message

2008-01-24 Thread Eric Butera
On Jan 24, 2008 6:20 PM, Rene Brehmer [EMAIL PROTECTED] wrote:
 Drew a blank off the archive, so here goes...

 I'm working on some forms for our company website, all of which simply have
 to be mailed to us by email.

 After verifying that the content of all the fields is valid and the proper
 type, it builds the email message as following. This all works great, but I
 want a simpler/easier way to reuse the code (we have 3 forms, with
 distinctively different content, but the mail process remains the same), so
 something that will do the below, but can be reduced to something like
 grabbing a text file and fill in the blanks would be nice, instead of this:

   // prepare message
   if(! $error) {
 $message = Information submitted with Tee Time booking form:\r\n;
 $message .= Name and address:\r\n\r\n;
 $message .= $name\r\n;
 $message .= $address\r\n;
 $message .= $city\r\n;
 $message .= $state $postcode\r\n\r\n;
 $message .= Email: $email\r\n;
 $message .= Phone: $phone\r\n;
 $message .= \r\n\r\nBooking info:\r\n\r\n;
 $message .= Arrival: $a_month $a_day\r\n;
 $message .= Departure: $d_month $d_day\r\n;
 $message .= Persons: $persons\r\n;
 $message .= Rooms: $rooms\r\n;
 $message .= \r\nGolf Courses\r\n\r\n;
 for($i = 1; $i  8; $i++) {
   if($_POST['course_'.$i] != 0) {
 $message .= 'Course: '.$_POST['course_'.$i].\r\n;
 $message .= 'Date: '.$_POST['month_'.$i].'
 '.$_POST['day_'.$i].\r\n;
 $message .= 'Time: '.$_POST['teetime_'.$i].\r\n;
 $message .= '# of golfers: '.$_POST['golfers_'.$i].\r\n;
   }
 }
 if(! empty($comments)) {
   $message .= \r\nComments:\r\n$comments\r\n;
 }
 $message .= \r\nUser Client Info:\r\n;
 $message .= 'User IP: '.$_SERVER['REMOTE_ADDR'].\r\nUser agent:
 .$_SERVER['HTTP_USER_AGENT'].\r\n\r\n;


 // NOTE: This code only builds the actual message, the headers are built
 elsewhere in the code.
 // This is our golf-package quote request (I work for a hotel) form, where
 you can book up to 7 tee times. Thus the iteration in the middle, to run
 through the 7 tee time fields.

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



Check out Zend_Mail.  It changed my life. :)

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



[PHP] Re: a better way to do a data import?

2008-01-21 Thread Dan
blackwater dev [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
I  have a text file that contains 200k rows.   These rows are to be 
imported
into our database.  The majority of them will already exists while a few 
are

new.  Here are a few options I've tried:

I've had php cycle through the file row by row and if the row is there,
delete it and do a straight insert but that took a while.

Now I have php get the row from the text file and then to array_combine 
with

a default array I have in the class so I can have key value pairs.  I then
take that generated array and do array_diff to the data array I pulled 
from

the db and I then have the columns that are different so I do an update on
only those columns for that specific row.  This is slow and after about
180,000 rows, php throws a memory error.  I'm resetting all my vars to 
NULL

at each iteration so am not sure what's up.


Anyone have a better way to do this?  In MySQL, I could simply a replace 
on

each row...but not in postgres.

Thanks!



Couldn't you just use PHP to rewrite the 200k row text file from just text, 
to actual insert commands?  Once you have that, most mysql interfaces have 
an import ability where you can give it a file which is a list of commands 
(insert, update, etc.) and it will run them itself.  That should be much 
faster.


- Dan 


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



Re: [PHP] what is better way to write the query

2007-11-05 Thread Shafiq Rehman
Hi,

If possible, write your inserts queries in a text file and use LOAD DATA for
bulk inserts.

-- 
Keep Smiling
Shafiq Rehman (ZCE)
http://www.phpgurru.com | http://shafiq.pk
Cell: +92 300 423 9385

On 11/2/07, Andrew Ballard [EMAIL PROTECTED] wrote:

 On Nov 2, 2007 10:41 AM, afan pasalic [EMAIL PROTECTED] wrote:
  ...is there any suggestion for the process of inserting up to 5K records
 at
  the time ...

 Is it possible to save your data to a text file and then use one of
 MySQL's built-in import queries? (I know in some situations it isn't
 an option because the PHP server and the MySQL server are not able to
 read from a common location.)

 Andrew

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




-- 
Keep Smiling
Shafiq Rehman (ZCE)
http://www.phpgurru.com | http://shafiq.pk
Cell: +92 300 423 9385


Re: [PHP] what is better way to write the query

2007-11-02 Thread afan pasalic
let me write the questions again:
what is the difference between these two queries?
is there any situation when it's better to use first vs. second solution?
is there any suggestion for the process of inserting up to 5K records at
the time or this number is so small to consider any optimization?

sorry for english :-)

-afan


afan pasalic wrote:
 hi,
 it's maybe more question for mysql list, but since php is involved
 too... :-)
 I have php script that inserts into mysql table couple hundreds of records.
 usually, it looks like:
 ?php
 // 1st record
 $query = INSERT INTO table (col_11, col_12, ... col_1n) VALUES
 ($value_11, $value_12,... $value_1n );
 mysql_query($query) or die ($mysql_error());

 // 2nd record
 $query = INSERT INTO table (col_21, col_22, ... col_2n) VALUES
 ($value_21, $value_22,... $value_2n );
 mysql_query($query) or die ($mysql_error());

 ...
 // last record
 $query = INSERT INTO table (col_m1, col_m2, ... col_mn) VALUES
 ($value_m1, $value_m2,... $value_mn );
 mysql_query($query) or die ($mysql_error());


 It also works this way:
 $query = INSERT INTO table (col_m1, col_m2, ... col_mn) VALUES;
 $query .= ($value_m1, $value_m2,... $value_mn ), ;
 $query .= ($value_21, $value_22,... $value_2n ), ;
 ...
 $query .= ($value_m1, $value_m2,... $value_mn );
 mysql_query($query) or die ($mysql_error());

 is what's the difference between these two queries?
 is there any situations when is better to use first vs. second?
 any suggestion for the process of inserting up to 5K records at the time
 or this number is so small to consider any optimization?

 thanks for any help.

 -afan

   

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



[PHP] what is better way to write the query

2007-11-02 Thread afan pasalic
hi,
it's maybe more question for mysql list, but since php is involved
too... :-)
I have php script that inserts into mysql table couple hundreds of records.
usually, it looks like:
?php
// 1st record
$query = INSERT INTO table (col_11, col_12, ... col_1n) VALUES
($value_11, $value_12,... $value_1n );
mysql_query($query) or die ($mysql_error());

// 2nd record
$query = INSERT INTO table (col_21, col_22, ... col_2n) VALUES
($value_21, $value_22,... $value_2n );
mysql_query($query) or die ($mysql_error());

...
// last record
$query = INSERT INTO table (col_m1, col_m2, ... col_mn) VALUES
($value_m1, $value_m2,... $value_mn );
mysql_query($query) or die ($mysql_error());


It also works this way:
$query = INSERT INTO table (col_m1, col_m2, ... col_mn) VALUES;
$query .= ($value_m1, $value_m2,... $value_mn ), ;
$query .= ($value_21, $value_22,... $value_2n ), ;
...
$query .= ($value_m1, $value_m2,... $value_mn );
mysql_query($query) or die ($mysql_error());

is what's the difference between these two queries?
is there any situations when is better to use first vs. second?
any suggestion for the process of inserting up to 5K records at the time
or this number is so small to consider any optimization?

thanks for any help.

-afan

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



Re: [PHP] what is better way to write the query

2007-11-02 Thread Jim Lucas

afan pasalic wrote:

hi,
it's maybe more question for mysql list, but since php is involved
too... :-)
I have php script that inserts into mysql table couple hundreds of records.
usually, it looks like:
?php
// 1st record
$query = INSERT INTO table (col_11, col_12, ... col_1n) VALUES
($value_11, $value_12,... $value_1n );
mysql_query($query) or die ($mysql_error());

// 2nd record
$query = INSERT INTO table (col_21, col_22, ... col_2n) VALUES
($value_21, $value_22,... $value_2n );
mysql_query($query) or die ($mysql_error());

...
// last record
$query = INSERT INTO table (col_m1, col_m2, ... col_mn) VALUES
($value_m1, $value_m2,... $value_mn );
mysql_query($query) or die ($mysql_error());


It also works this way:
$query = INSERT INTO table (col_m1, col_m2, ... col_mn) VALUES;
$query .= ($value_m1, $value_m2,... $value_mn ), ;
$query .= ($value_21, $value_22,... $value_2n ), ;
...
$query .= ($value_m1, $value_m2,... $value_mn );
mysql_query($query) or die ($mysql_error());

is what's the difference between these two queries?
is there any situations when is better to use first vs. second?
any suggestion for the process of inserting up to 5K records at the time
or this number is so small to consider any optimization?

thanks for any help.

-afan



I would perform multiple inserts @ a time.  This way you save yourself some time by not having mysql 
rebuild the indexes, if any exist, after each insert statement.


--
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

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



Re: [PHP] what is better way to write the query

2007-11-02 Thread Stut

Jim Lucas wrote:

afan pasalic wrote:

hi,
it's maybe more question for mysql list, but since php is involved
too... :-)
I have php script that inserts into mysql table couple hundreds of 
records.

usually, it looks like:
?php
// 1st record
$query = INSERT INTO table (col_11, col_12, ... col_1n) VALUES
($value_11, $value_12,... $value_1n );
mysql_query($query) or die ($mysql_error());

// 2nd record
$query = INSERT INTO table (col_21, col_22, ... col_2n) VALUES
($value_21, $value_22,... $value_2n );
mysql_query($query) or die ($mysql_error());

...
// last record
$query = INSERT INTO table (col_m1, col_m2, ... col_mn) VALUES
($value_m1, $value_m2,... $value_mn );
mysql_query($query) or die ($mysql_error());


It also works this way:
$query = INSERT INTO table (col_m1, col_m2, ... col_mn) VALUES;
$query .= ($value_m1, $value_m2,... $value_mn ), ;
$query .= ($value_21, $value_22,... $value_2n ), ;
...
$query .= ($value_m1, $value_m2,... $value_mn );
mysql_query($query) or die ($mysql_error());

is what's the difference between these two queries?
is there any situations when is better to use first vs. second?
any suggestion for the process of inserting up to 5K records at the time
or this number is so small to consider any optimization?

thanks for any help.

-afan



I would perform multiple inserts @ a time.  This way you save yourself 
some time by not having mysql rebuild the indexes, if any exist, after 
each insert statement.


Indeed, but bear in mind that there is a limit on the size of queries 
MySQL will accept. Look up the MySQL max_packet_size for details.


-Stut

--
http://stut.net/

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



Re: [PHP] what is better way to write the query

2007-11-02 Thread Stut

afan pasalic wrote:

Stut wrote:

Jim Lucas wrote:

afan pasalic wrote:

hi,
it's maybe more question for mysql list, but since php is involved
too... :-)
I have php script that inserts into mysql table couple hundreds of
records.
usually, it looks like:
?php
// 1st record
$query = INSERT INTO table (col_11, col_12, ... col_1n) VALUES
($value_11, $value_12,... $value_1n );
mysql_query($query) or die ($mysql_error());

// 2nd record
$query = INSERT INTO table (col_21, col_22, ... col_2n) VALUES
($value_21, $value_22,... $value_2n );
mysql_query($query) or die ($mysql_error());

...
// last record
$query = INSERT INTO table (col_m1, col_m2, ... col_mn) VALUES
($value_m1, $value_m2,... $value_mn );
mysql_query($query) or die ($mysql_error());


It also works this way:
$query = INSERT INTO table (col_m1, col_m2, ... col_mn) VALUES;
$query .= ($value_m1, $value_m2,... $value_mn ), ;
$query .= ($value_21, $value_22,... $value_2n ), ;
...
$query .= ($value_m1, $value_m2,... $value_mn );
mysql_query($query) or die ($mysql_error());

is what's the difference between these two queries?
is there any situations when is better to use first vs. second?
any suggestion for the process of inserting up to 5K records at the
time
or this number is so small to consider any optimization?

thanks for any help.

-afan


I would perform multiple inserts @ a time.  This way you save
yourself some time by not having mysql rebuild the indexes, if any
exist, after each insert statement.

Indeed, but bear in mind that there is a limit on the size of queries
MySQL will accept. Look up the MySQL max_packet_size for details.

-Stut


I didn't find max_packet_size in my my.cnf, but found max_allowed_packet
- that's the same, right?


Indeed, my memory ain't what it used to be.


under [mysqld]
max_allowed_packet = 1M
shouldn't be 1M enough for the query?


Depends how big it's gonna get, which is for you to judge.

-Stut

--
http://stut.net/

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



Re: [PHP] what is better way to write the query

2007-11-02 Thread Andrew Ballard
On Nov 2, 2007 10:41 AM, afan pasalic [EMAIL PROTECTED] wrote:
 ...is there any suggestion for the process of inserting up to 5K records at
 the time ...

Is it possible to save your data to a text file and then use one of
MySQL's built-in import queries? (I know in some situations it isn't
an option because the PHP server and the MySQL server are not able to
read from a common location.)

Andrew

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



Re: [PHP] what is better way to write the query

2007-11-02 Thread Stut

afan pasalic wrote:

Stut wrote:

afan pasalic wrote:

Stut wrote:

Jim Lucas wrote:

afan pasalic wrote:

hi,
it's maybe more question for mysql list, but since php is involved
too... :-)
I have php script that inserts into mysql table couple hundreds of
records.
usually, it looks like:
?php
// 1st record
$query = INSERT INTO table (col_11, col_12, ... col_1n) VALUES
($value_11, $value_12,... $value_1n );
mysql_query($query) or die ($mysql_error());

// 2nd record
$query = INSERT INTO table (col_21, col_22, ... col_2n) VALUES
($value_21, $value_22,... $value_2n );
mysql_query($query) or die ($mysql_error());

...
// last record
$query = INSERT INTO table (col_m1, col_m2, ... col_mn) VALUES
($value_m1, $value_m2,... $value_mn );
mysql_query($query) or die ($mysql_error());


It also works this way:
$query = INSERT INTO table (col_m1, col_m2, ... col_mn) VALUES;
$query .= ($value_m1, $value_m2,... $value_mn ), ;
$query .= ($value_21, $value_22,... $value_2n ), ;
...
$query .= ($value_m1, $value_m2,... $value_mn );
mysql_query($query) or die ($mysql_error());

is what's the difference between these two queries?
is there any situations when is better to use first vs. second?
any suggestion for the process of inserting up to 5K records at the
time
or this number is so small to consider any optimization?

thanks for any help.

-afan


I would perform multiple inserts @ a time.  This way you save
yourself some time by not having mysql rebuild the indexes, if any
exist, after each insert statement.

Indeed, but bear in mind that there is a limit on the size of queries
MySQL will accept. Look up the MySQL max_packet_size for details.

-Stut


I didn't find max_packet_size in my my.cnf, but found max_allowed_packet
- that's the same, right?

Indeed, my memory ain't what it used to be.


under [mysqld]
max_allowed_packet = 1M
shouldn't be 1M enough for the query?

Depends how big it's gonna get, which is for you to judge.

-Stut


I'll run some tests and find what would be the best value.
But, multiple inserts (solution no. 2) is the answer, right?


It's definitely more efficient, yes.

-Stut

--
http://stut.net/

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



Re: [PHP] what is better way to write the query

2007-11-02 Thread afan pasalic
Stut wrote:
 afan pasalic wrote:
 Stut wrote:
 Jim Lucas wrote:
 afan pasalic wrote:
 hi,
 it's maybe more question for mysql list, but since php is involved
 too... :-)
 I have php script that inserts into mysql table couple hundreds of
 records.
 usually, it looks like:
 ?php
 // 1st record
 $query = INSERT INTO table (col_11, col_12, ... col_1n) VALUES
 ($value_11, $value_12,... $value_1n );
 mysql_query($query) or die ($mysql_error());

 // 2nd record
 $query = INSERT INTO table (col_21, col_22, ... col_2n) VALUES
 ($value_21, $value_22,... $value_2n );
 mysql_query($query) or die ($mysql_error());

 ...
 // last record
 $query = INSERT INTO table (col_m1, col_m2, ... col_mn) VALUES
 ($value_m1, $value_m2,... $value_mn );
 mysql_query($query) or die ($mysql_error());


 It also works this way:
 $query = INSERT INTO table (col_m1, col_m2, ... col_mn) VALUES;
 $query .= ($value_m1, $value_m2,... $value_mn ), ;
 $query .= ($value_21, $value_22,... $value_2n ), ;
 ...
 $query .= ($value_m1, $value_m2,... $value_mn );
 mysql_query($query) or die ($mysql_error());

 is what's the difference between these two queries?
 is there any situations when is better to use first vs. second?
 any suggestion for the process of inserting up to 5K records at the
 time
 or this number is so small to consider any optimization?

 thanks for any help.

 -afan

 I would perform multiple inserts @ a time.  This way you save
 yourself some time by not having mysql rebuild the indexes, if any
 exist, after each insert statement.
 Indeed, but bear in mind that there is a limit on the size of queries
 MySQL will accept. Look up the MySQL max_packet_size for details.

 -Stut

 I didn't find max_packet_size in my my.cnf, but found max_allowed_packet
 - that's the same, right?

 Indeed, my memory ain't what it used to be.

 under [mysqld]
 max_allowed_packet = 1M
 shouldn't be 1M enough for the query?

 Depends how big it's gonna get, which is for you to judge.

 -Stut

I'll run some tests and find what would be the best value.
But, multiple inserts (solution no. 2) is the answer, right?

-afan

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



Re: [PHP] what is better way to write the query

2007-11-02 Thread afan pasalic
Stut wrote:
 Jim Lucas wrote:
 afan pasalic wrote:
 hi,
 it's maybe more question for mysql list, but since php is involved
 too... :-)
 I have php script that inserts into mysql table couple hundreds of
 records.
 usually, it looks like:
 ?php
 // 1st record
 $query = INSERT INTO table (col_11, col_12, ... col_1n) VALUES
 ($value_11, $value_12,... $value_1n );
 mysql_query($query) or die ($mysql_error());

 // 2nd record
 $query = INSERT INTO table (col_21, col_22, ... col_2n) VALUES
 ($value_21, $value_22,... $value_2n );
 mysql_query($query) or die ($mysql_error());

 ...
 // last record
 $query = INSERT INTO table (col_m1, col_m2, ... col_mn) VALUES
 ($value_m1, $value_m2,... $value_mn );
 mysql_query($query) or die ($mysql_error());


 It also works this way:
 $query = INSERT INTO table (col_m1, col_m2, ... col_mn) VALUES;
 $query .= ($value_m1, $value_m2,... $value_mn ), ;
 $query .= ($value_21, $value_22,... $value_2n ), ;
 ...
 $query .= ($value_m1, $value_m2,... $value_mn );
 mysql_query($query) or die ($mysql_error());

 is what's the difference between these two queries?
 is there any situations when is better to use first vs. second?
 any suggestion for the process of inserting up to 5K records at the
 time
 or this number is so small to consider any optimization?

 thanks for any help.

 -afan


 I would perform multiple inserts @ a time.  This way you save
 yourself some time by not having mysql rebuild the indexes, if any
 exist, after each insert statement.

 Indeed, but bear in mind that there is a limit on the size of queries
 MySQL will accept. Look up the MySQL max_packet_size for details.

 -Stut

I didn't find max_packet_size in my my.cnf, but found max_allowed_packet
- that's the same, right?
under [mysqld]
max_allowed_packet = 1M
shouldn't be 1M enough for the query?

-afan

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



[PHP] [X-POST] Fastest way to dump this huge table

2007-05-02 Thread Brian Dunning
I have a huge MySQL table, 2.1 million records, 200MB. Once a week I  
need to dump it in CSV format and zip the file.


This is not on my server, and it's in production, so I don't want to  
risk testing different methods and possibly hanging up their server  
for a period of time, so I wanted to seek advice here first to find  
what's the best way to proceed.


I can easily use PHP to query the table for the results I want and  
write a file line by line and then zip it, but I'm worried that might  
take too long and hang up the machine. The other way to go is some  
kind of sql dump command, which I guess would be faster, but not sure  
how much control I'd have over the exact format of the file. Any  
suggestions which way I should proceed? Not hanging up their server  
is my prime concern.


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



Re: [PHP] [X-POST] Fastest way to dump this huge table

2007-05-02 Thread Richard Davey

Brian Dunning wrote:

I have a huge MySQL table, 2.1 million records, 200MB. Once a week I 
need to dump it in CSV format and zip the file.


This is not on my server, and it's in production, so I don't want to 
risk testing different methods and possibly hanging up their server for 
a period of time, so I wanted to seek advice here first to find what's 
the best way to proceed.


I can easily use PHP to query the table for the results I want and write 
a file line by line and then zip it, but I'm worried that might take too 
long and hang up the machine. The other way to go is some kind of sql 
dump command, which I guess would be faster, but not sure how much 
control I'd have over the exact format of the file. Any suggestions 
which way I should proceed? Not hanging up their server is my prime 
concern.


If hogging their server is of prime concern then ideally you either need 
to (a) schedule down time for the site while the back-up happens, or (b) 
replicate the data to another MySQL server, and back-up that.


I can't see any reason why you need to bring PHP into the equation here, 
MySQL has more than enough native tools to do exactly what you need - 
and probably a butt-load faster too.


Cheers,

Rich
--
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

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



Re: [PHP] [X-POST] Fastest way to dump this huge table

2007-05-02 Thread David Giragosian

On 5/2/07, Richard Davey [EMAIL PROTECTED] wrote:


Brian Dunning wrote:

 I have a huge MySQL table, 2.1 million records, 200MB. Once a week I
 need to dump it in CSV format and zip the file.

 This is not on my server, and it's in production, so I don't want to
 risk testing different methods and possibly hanging up their server for
 a period of time, so I wanted to seek advice here first to find what's
 the best way to proceed.

 I can easily use PHP to query the table for the results I want and write
 a file line by line and then zip it, but I'm worried that might take too
 long and hang up the machine. The other way to go is some kind of sql
 dump command, which I guess would be faster, but not sure how much
 control I'd have over the exact format of the file. Any suggestions
 which way I should proceed? Not hanging up their server is my prime
 concern.

If hogging their server is of prime concern then ideally you either need
to (a) schedule down time for the site while the back-up happens, or (b)
replicate the data to another MySQL server, and back-up that.

I can't see any reason why you need to bring PHP into the equation here,
MySQL has more than enough native tools to do exactly what you need -
and probably a butt-load faster too.

Cheers,

Rich




Brian,

As a comparison, on a *nix master/slave configuration, I'm mysqldumping
nightly a database that's always growing and now is over a 1GB in size. The
dump takes about 20 seconds to finish. Assuming a linear relationship, your
200MB backup should only tie up the db server for around 5 seconds.

Bzipping the .sql file takes infinitiely longer, almost an hour, but a lower
compression ratio should take only 1/4 to 1/3 as long.

I'd say give some attention to the zip method you use.

HTH,

David


  1   2   3   4   5   >