Solved

Stopping CGI/Perl  when Browser stops listening

Posted on 1998-07-24
1
202 Views
Last Modified: 2013-12-25
I have made a CGI-Perl script which feeds back multple JPG images to a <IMG> tag client call.  The multi images can run up to 200 JPGs.  One thing that's for sure is the client won't sit there for all 200 JPGS to show on their screen as an animation (they'll leave my page to somewhere else).  Now if this is the case, I'd hate for my CGI script to "keep sending" JPG images if there's no one watching it.

Therefore, I'd like to have my Perl script "immediately" stop sending images and quit if the client browser has stopped accepting images.  I remeber such a command exists in Perl but I totally forget what it is.  Would you know the answer?

Thanks.
0
Comment
Question by:ljaques
1 Comment
 
LVL 6

Accepted Solution

by:
alamo earned 0 total points
ID: 1831149
You probably have a line to copy the image file to STDOUT which looks something like:
print <IN>;

Change it to:
print (<IN>) || last;

When the user hits stop on the browser, the server kills STDOUT and thus print fails. (Bet you didn't know print was a function that returns true or false, most people don't use it that way). What you are going to print needs to be enclised in () so that it doesn't try to print <IN>||last, which won't work.

Hope this helps!

p.s. I would have told you this last time if I had realized it, I knew it was possible but had never actually figured out how to do it. Now I have :-)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now