Re: Intense CPU strain....suggestions



cbmeeks wrote:
Well, you could kick off a batch job to do your resizing, then return to
the user. That way it can keep processing the images. The only thing
you'll have to handle is when the user wants to display his gallery
before it's ready.


That's exactly how I want to do it. I just don't know the best way to
execute it. I like the idea of having an XML-RPC server running but I
am concerned with security (as I should be).

So, let's say I have the following code (using CI):

...
$this->Upload->do_uploads(); // handle the actual uploading.

$this->Photos->do_resizing(); // handle the resizing

redirect('waiting');
....

"Waiting" doesn't get kicked off until after do_resizing (sorry, new
to PHP). I'm sure there is a smarter way. I'd like to avoid pop-ups,
iframes, javascript, etc if possible.

I also thought about having the "do_resizing" simple add some records
to a db and have a program running on the server full time that checks
the db frequently. But wouldn't that be wasteful? I like the idea of
programs laying dormant until something kicks it in the pants and says
"do something!" lol

Thanks

cbmeeks
http://www.signaldev.com





First of all, the redirect won't happen until the code reaches there - which is after your resizing. So that's normal operation.

You could have a cron job kicked off every few minutes to resize the pictures, but again, you'll run into the problem that after uploading the user won't be able to see the pictures he's just uploaded - at least in various sizes.

You could use shell_exec() to start off a background process, i.e. (assuming Unix/Linux):

shell_exec('nohup myprog file1 file2 file3 2> /dev/null &');

nohup says to execute a command without hangups and no output, 2> /dev/null throws away any error messages, and the '&' at the end says run in the background.

You'll still run into a problem that the resizing might not occur as fast as the user wants to display it; you'll have to be able to handle this in your display routines.

Alternatively, you could do something like:

<body>
echo 'Resizing your images, please wait...<br>';
flush();
$this->Upload->do_uploads(); // handle the actual uploading.
$this->Photos->do_resizing(); // handle the resizing
echo 'Done!. <a href="nextpage.php">Click here to continue</a>';
</body>

The flush() works with most browsers if you keep the html simple - it forces the output to the browser and the browser displays it. But if you start to get fancy (i.e. tables, etc.), many browsers will wait for the end of the element to actually display.

The only problem with this is, once you've sent *any* output to the browser, you can't redirect them to another page via php (you could use an html redirect). That's why the link.

Just some ideas.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: 800x600
    ... >>> browser window shrinks you end up with a photo with one word per ... So if you want to display images at a size ...
    (uk.net.web.authoring)
  • Re: 800x600
    ... >> larger browser window and a lot of the space is then blank. ... > display your page. ... Size), images cannot. ...
    (uk.net.web.authoring)
  • Re: 800x600
    ... > resized by the user if his browser has a font scaling factor (eg IE's ... text - this scales all images and fixed-size elements accordingly. ... > So if you want to display images at a size that displays them well (if ... So someone with a standard GUI browser on a ...
    (uk.net.web.authoring)
  • Re: Images not displaying properly in my own browsers but works el
    ... (check View Source in the browser and search for the image name. ... If the image is removed totally, then Norton is probably to blame - ... >> Alarm) may be removing the images from the page as the page is ... >>> they display, but they don't display in either Firefox or IE6 on ...
    (microsoft.public.frontpage.programming)
  • Re: Can Tk do this
    ... I don't want the images to display in the user's browser. ... or a perl/Tk viewer. ...
    (comp.lang.perl.tk)