Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread Per Jessen
Dave M G wrote:

 I contacted my web host provider, and they recommended increasing the
 allowed allocation limit in /etc/php.ini.
 
 Right now my allocation limit, assuming I'm looking at the right
 setting is 8 megabytes:
 
 memory_limit = 8M  ; Maximum amount of memory a script may consume
 (8MB)
 
 What would be a recommended size? While I want to have enough to work
 with large images, I don't want to overload the server.

Unless you are constrained by memory in general, I would say 64M.  But
check how much memory you have and how many pictures you expect to
process concurrently. 

 Actually, I have no idea what the potential dangers are.  

Using up all available memory is the only real risk.  It might lead to
swapping which in turn will most likely increase response times. 


/Per Jessen, Zürich


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



Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread tedd

At 6:48 PM +0900 4/16/08, Dave M G wrote:

PHP list,

I have a PHP script that resizes an image. It takes just about 
whatever size and shrinks and crops it down to 320X240.


I've found that these days, it's not uncommon for people to take 
images straight off their digital camera, which can be 3000X2000 
pixels in image size, even if the jpeg file containing the image is 
only 200 KB. When working with the image, it gets uncompressed and 
takes up a lot of memory.


You might want to look into using javascript to trim the file down to 
a respectable size before uploading.


Cheers,

tedd

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

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



Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread Daniel Brown
On Wed, Apr 16, 2008 at 5:48 AM, Dave M G [EMAIL PROTECTED] wrote:
 PHP list,

  I have a PHP script that resizes an image. It takes just about whatever
 size and shrinks and crops it down to 320X240.

[snip!]

  So sometimes I've seen an error in my logs that says:

  Fatal error: Allowed memory size of 8388608 bytes
  exhausted (tried to allocate 8000 bytes) in
  /home/public_html/Action.php on line 153.
[snip!]

  What would be a recommended size? While I want to have enough to work with
 large images, I don't want to overload the server.

I set the server-wide setting on most of my servers to 64MB.  This
includes my shared hosting servers, where resources are then monitored
otherwise and then clients who may overuse or abuse resources may be
bumped to a more powerful system (VPS, dedicated, or even just a
higher shared plan).  So I'd recommend using 64MB, but monitoring
traffic as well --- because that 64MB max limit will be for each
execution of each script.  So if you have 100 simultaneous connections
each using the maximum memory allowed by configuration, you're looking
at ~6.4GB memory --- clearly into swap space, and not an optimal
situation.

-- 
/Daniel P. Brown
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!

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



Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread Andrew Ballard
On Wed, Apr 16, 2008 at 7:56 AM, tedd [EMAIL PROTECTED] wrote:
 At 6:48 PM +0900 4/16/08, Dave M G wrote:

  PHP list,
 
  I have a PHP script that resizes an image. It takes just about whatever
 size and shrinks and crops it down to 320X240.
 
  I've found that these days, it's not uncommon for people to take images
 straight off their digital camera, which can be 3000X2000 pixels in image
 size, even if the jpeg file containing the image is only 200 KB. When
 working with the image, it gets uncompressed and takes up a lot of memory.
 

  You might want to look into using javascript to trim the file down to a
 respectable size before uploading.

  Cheers,

  tedd

I'd be interested in seeing an example of how you actually plan on
doing that, Tedd. JavaScript can't access the file from an input
field, and I'm not aware of any JavaScript image handling functions
either.

Andrew

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



Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread Daniel Brown
On Wed, Apr 16, 2008 at 6:07 AM, Per Jessen [EMAIL PROTECTED] wrote:

   Actually, I have no idea what the potential dangers are.

  Using up all available memory is the only real risk.  It might lead to
  swapping which in turn will most likely increase response times.

And on a shared host, the likelihood of increased billing for
overuse of memory.  If it's going to be that resource-intensive, it
may be better to consider moving to a VPS or dedicated server.

I removed my signature from this email so it doesn't look like I'm
stating this to try to sell my own stuff.  ;-P

-- 
/Daniel P. Brown

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



Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread Daniel Brown
On Wed, Apr 16, 2008 at 7:56 AM, tedd [EMAIL PROTECTED] wrote:
 At 6:48 PM +0900 4/16/08, Dave M G wrote:

  PHP list,
 
  I have a PHP script that resizes an image. It takes just about whatever
 size and shrinks and crops it down to 320X240.
 
  I've found that these days, it's not uncommon for people to take images
 straight off their digital camera, which can be 3000X2000 pixels in image
 size, even if the jpeg file containing the image is only 200 KB. When
 working with the image, it gets uncompressed and takes up a lot of memory.
 

  You might want to look into using javascript to trim the file down to a
 respectable size before uploading.

I've never seen JavaScript's ability to work with image resizing
and such.  Are you suggesting using it instead to say, that file is
too big, before it's uploaded?  If that's the case, it may not work
in Dave's situation, since he expects large files already, and
therefore has the resizing script(s) in place.

If I'm not totally off-point, I think the memory issue is more of
GD/Imagemagick being a resource hog than the actual file size, since
he pointed out that a megapixel image is sometimes still only 200K.

-- 
/Daniel P. Brown
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!

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



Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread Per Jessen
Daniel Brown wrote:

 On Wed, Apr 16, 2008 at 6:07 AM, Per Jessen [EMAIL PROTECTED] wrote:

   Actually, I have no idea what the potential dangers are.

  Using up all available memory is the only real risk.  It might
  lead to swapping which in turn will most likely increase response
  times.
 
 And on a shared host, the likelihood of increased billing for
 overuse of memory. 

Except a shared hoster would probably not permit anyone to change
php.ini :-)


/Per Jessen, Zürich


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



Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread Daniel Brown
On Wed, Apr 16, 2008 at 9:57 AM, Per Jessen [EMAIL PROTECTED] wrote:
 Daniel Brown wrote:
  
   And on a shared host, the likelihood of increased billing for
   overuse of memory.

  Except a shared hoster would probably not permit anyone to change
  php.ini :-)

I do.  A lot of them do.

-- 
/Daniel P. Brown
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!

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



Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread tedd

At 9:41 AM -0400 4/16/08, Andrew Ballard wrote:

On Wed, Apr 16, 2008 at 7:56 AM, tedd [EMAIL PROTECTED] wrote:

 At 6:48 PM +0900 4/16/08, Dave M G wrote:

  PHP list,
 
  I have a PHP script that resizes an image. It takes just about whatever
 size and shrinks and crops it down to 320X240.
 
  I've found that these days, it's not uncommon for people to take images
 straight off their digital camera, which can be 3000X2000 pixels in image
 size, even if the jpeg file containing the image is only 200 KB. When
 working with the image, it gets uncompressed and takes up a lot of memory.
 

  You might want to look into using javascript to trim the file down to a
 respectable size before uploading.

  Cheers,

  tedd


I'd be interested in seeing an example of how you actually plan on
doing that, Tedd. JavaScript can't access the file from an input
field, and I'm not aware of any JavaScript image handling functions
either.

Andrew



I saw one the other day that caught my eye -- will look into it.

Cheers,

tedd

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

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



Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread Per Jessen
Daniel Brown wrote:

 On Wed, Apr 16, 2008 at 9:57 AM, Per Jessen [EMAIL PROTECTED] wrote:
 Daniel Brown wrote:
  
   And on a shared host, the likelihood of increased billing for
   overuse of memory.

  Except a shared hoster would probably not permit anyone to change
  php.ini :-)
 
 I do.  A lot of them do.

I'm curious - why?  To me php.ini seems to be exactly the kind of thing
you wouldn't the user to fiddle with - in a shared environment.  



/Per Jessen, Zürich


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



Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread Andrew Ballard
On Wed, Apr 16, 2008 at 9:59 AM, tedd [EMAIL PROTECTED] wrote:

 At 9:41 AM -0400 4/16/08, Andrew Ballard wrote:

  On Wed, Apr 16, 2008 at 7:56 AM, tedd [EMAIL PROTECTED] wrote:
 
At 6:48 PM +0900 4/16/08, Dave M G wrote:
  
 PHP list,

 I have a PHP script that resizes an image. It takes just about
 whatever
size and shrinks and crops it down to 320X240.

 I've found that these days, it's not uncommon for people to take
 images
straight off their digital camera, which can be 3000X2000 pixels in
 image
size, even if the jpeg file containing the image is only 200 KB. When
working with the image, it gets uncompressed and takes up a lot of
 memory.

  
You might want to look into using javascript to trim the file down to a
respectable size before uploading.
  
Cheers,
  
tedd
  
 
  I'd be interested in seeing an example of how you actually plan on
  doing that, Tedd. JavaScript can't access the file from an input
  field, and I'm not aware of any JavaScript image handling functions
  either.
 
  Andrew
 


  I saw one the other day that caught my eye -- will look into it.



  Cheers,

  tedd

The first problem I see implementing the approach is the JavaScript
sandbox. JavaScript is allowed to read the text of the input file
field (and thus know the file name and path once a file has been
selected); it cannot access the disk to actually get to the image or
do anything with it. From here, I'm thinking there are a couple things
you could do with JavaScript. The first would be to embed the image
into the web page using an IMG tag, which would allow you to determine
the pixel dimensions (but not the actual file size). The second would
be what Gmail seems to do, and actually upload the form to their
server with some sort of AJAX request, at which time your server could
return information on the size of the file. However, if the file is
too large, you're back to the original problem of needing to increase
the RAM limit in PHP.

The second problem is, as I said, I'm not aware of any JavaScript that
can manipulate the image. JavaScript can cause the display of an image
to be resized within the browser, but that doesn't actually affect the
stored file. I don't know, but I guess if you could actually get to
the bits, you could probably write an algorithm in JavaScript to
resize an image by manipulating the bits, but I think it would be
dreadfully slow if it would even run without running out of resources.

I think the only pure-client options are either Java (which would
require special permissions to get out of its own sandbox) or ActiveX.

If you know of some other approach, I'd be interested to see how it works.

Andrew

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



Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread Daniel Brown
On Wed, Apr 16, 2008 at 10:36 AM, Per Jessen [EMAIL PROTECTED] wrote:

  I'm curious - why?  To me php.ini seems to be exactly the kind of thing
  you wouldn't the user to fiddle with - in a shared environment.

To allow flexibility for the user, and give them the opportunity
to customize the account to their needs.  The rest of the monitors and
filters cover the server in case they do anything extremely stupid,
but other than damaging their own things by turning register_globals
on, or running their quotas to the limit allowed by the balancers
(exceeding their allotted memory usage, for example), they can't
damage the rest of the server.

It should also be mentioned that all accounts on my servers are
chroot'd (jailed), with suExec running for each.  It's as if they're
the only one on the server (such as with a VPS), but without root
access, and with more limited resources.

-- 
/Daniel P. Brown
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!

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



Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread Per Jessen
Daniel Brown wrote:

 On Wed, Apr 16, 2008 at 10:36 AM, Per Jessen [EMAIL PROTECTED] wrote:

  I'm curious - why?  To me php.ini seems to be exactly the kind of
  thing you wouldn't the user to fiddle with - in a shared
  environment.
 
 To allow flexibility for the user, and give them the opportunity
 to customize the account to their needs. 

I guess it's a matter of preference - I tend to think that a shared
hosting user is best restricted to whatever changes he can do
in .htaccess (with php_admin_flag etc.).  
Mind you, it's not like I have hundreds of hosting customers, so maybe
my horizont is a little limited here. 


/Per Jessen, Zürich


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



Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread tedd

At 10:53 AM -0400 4/16/08, Andrew Ballard wrote:

On Wed, Apr 16, 2008 at 9:59 AM, tedd [EMAIL PROTECTED] wrote:

   I saw one the other day that caught my eye -- will look into it.



The first problem I see implementing the approach is the JavaScript
sandbox. JavaScript is allowed to read the text of the input file
field (and thus know the file name and path once a file has been
selected); it cannot access the disk to actually get to the image or
do anything with it. From here, I'm thinking there are a couple things
you could do with JavaScript. The first would be to embed the image
into the web page using an IMG tag, which would allow you to determine
the pixel dimensions (but not the actual file size). The second would
be what Gmail seems to do, and actually upload the form to their
server with some sort of AJAX request, at which time your server could
return information on the size of the file. However, if the file is
too large, you're back to the original problem of needing to increase
the RAM limit in PHP.

The second problem is, as I said, I'm not aware of any JavaScript that
can manipulate the image. JavaScript can cause the display of an image
to be resized within the browser, but that doesn't actually affect the
stored file. I don't know, but I guess if you could actually get to
the bits, you could probably write an algorithm in JavaScript to
resize an image by manipulating the bits, but I think it would be
dreadfully slow if it would even run without running out of resources.

I think the only pure-client options are either Java (which would
require special permissions to get out of its own sandbox) or ActiveX.

If you know of some other approach, I'd be interested to see how it works.

Andrew



Andrew:

I think you are right -- I wasn't able to resize the image. Here's 
the link that caught my eye, but it doesn't work as described:


http://javascript.internet.com/forms/image-upload-preview.html

Cheers,

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

Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread Daniel Brown
On Wed, Apr 16, 2008 at 11:42 AM, Per Jessen [EMAIL PROTECTED] wrote:
 Daniel Brown wrote:

  I guess it's a matter of preference - I tend to think that a shared
  hosting user is best restricted to whatever changes he can do
  in .htaccess (with php_admin_flag etc.).

I allow overrides in .htaccess, too.  Not sure what your thinking
is on that.

  Mind you, it's not like I have hundreds of hosting customers, so maybe
  my horizont is a little limited here.

I don't have hundreds right now either.  I had a company several
years ago, which I've since sold, that had about three hundred
accounts, but any more, I like to keep lower numbers per server.

-- 
/Daniel P. Brown
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!

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



Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread David Giragosian
On 4/16/08, tedd [EMAIL PROTECTED] wrote:

 At 10:53 AM -0400 4/16/08, Andrew Ballard wrote:

  On Wed, Apr 16, 2008 at 9:59 AM, tedd [EMAIL PROTECTED] wrote:
 
 I saw one the other day that caught my eye -- will look into it.
 
  
   The first problem I see implementing the approach is the JavaScript
  sandbox. JavaScript is allowed to read the text of the input file
  field (and thus know the file name and path once a file has been
  selected); it cannot access the disk to actually get to the image or
  do anything with it. From here, I'm thinking there are a couple things
  you could do with JavaScript. The first would be to embed the image
  into the web page using an IMG tag, which would allow you to determine
  the pixel dimensions (but not the actual file size). The second would
  be what Gmail seems to do, and actually upload the form to their
  server with some sort of AJAX request, at which time your server could
  return information on the size of the file. However, if the file is
  too large, you're back to the original problem of needing to increase
  the RAM limit in PHP.
 
  The second problem is, as I said, I'm not aware of any JavaScript that
  can manipulate the image. JavaScript can cause the display of an image
  to be resized within the browser, but that doesn't actually affect the
  stored file. I don't know, but I guess if you could actually get to
  the bits, you could probably write an algorithm in JavaScript to
  resize an image by manipulating the bits, but I think it would be
  dreadfully slow if it would even run without running out of resources.
 
  I think the only pure-client options are either Java (which would
  require special permissions to get out of its own sandbox) or ActiveX.
 
  If you know of some other approach, I'd be interested to see how it
  works.
 
  Andrew
 


 Andrew:

 I think you are right -- I wasn't able to resize the image. Here's the
 link that caught my eye, but it doesn't work as described:

 http://javascript.internet.com/forms/image-upload-preview.html

 Cheers,

 tedd
 --



It worked for me using IE on XP.

David


Re: [PHP] Memory limit of 8 MB not enough

2008-04-16 Thread Andrew Ballard
On Wed, Apr 16, 2008 at 12:00 PM, David Giragosian
[EMAIL PROTECTED] wrote:

 On 4/16/08, tedd [EMAIL PROTECTED] wrote:
  
   At 10:53 AM -0400 4/16/08, Andrew Ballard wrote:
  
On Wed, Apr 16, 2008 at 9:59 AM, tedd [EMAIL PROTECTED] wrote:
   
   I saw one the other day that caught my eye -- will look into it.
   

 The first problem I see implementing the approach is the JavaScript
sandbox. JavaScript is allowed to read the text of the input file
field (and thus know the file name and path once a file has been
selected); it cannot access the disk to actually get to the image or
do anything with it. From here, I'm thinking there are a couple things
you could do with JavaScript. The first would be to embed the image
into the web page using an IMG tag, which would allow you to determine
the pixel dimensions (but not the actual file size). The second would
be what Gmail seems to do, and actually upload the form to their
server with some sort of AJAX request, at which time your server could
return information on the size of the file. However, if the file is
too large, you're back to the original problem of needing to increase
the RAM limit in PHP.
   
The second problem is, as I said, I'm not aware of any JavaScript that
can manipulate the image. JavaScript can cause the display of an image
to be resized within the browser, but that doesn't actually affect the
stored file. I don't know, but I guess if you could actually get to
the bits, you could probably write an algorithm in JavaScript to
resize an image by manipulating the bits, but I think it would be
dreadfully slow if it would even run without running out of resources.
   
I think the only pure-client options are either Java (which would
require special permissions to get out of its own sandbox) or ActiveX.
   
If you know of some other approach, I'd be interested to see how it
works.
   
Andrew
   
  
  
   Andrew:
  
   I think you are right -- I wasn't able to resize the image. Here's the
   link that caught my eye, but it doesn't work as described:
  
   http://javascript.internet.com/forms/image-upload-preview.html
  
   Cheers,
  
   tedd
   --
  


  It worked for me using IE on XP.

  David


I get nothing in either browser.

FF: only the first header line; no content
HTTP/0.9 200 OK

IE:
 The page cannot be displayed
The page you are looking for is currently unavailable. The Web site
might be experiencing technical difficulties, or you may need to
adjust your browser settings.
[snip]
Cannot find server or DNS Error



Andrew

HTTP/0.9 200 OK

Andrew

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