in reply to Re^8: Broken image link when calling CGI from img tag
in thread Broken image link when calling CGI from img tag

The image IS getting generated just fine

You've said that before, but never mentioned when it is generated just fine. Which is kinda important, when it comes to timing issues.

(Note that a check with -e only checks if the file itself exists, not if it is fully written, a valid image, and readable.)

I am not sure what measures to take to make the image load the first time the page is loaded.

Point is, if the image is generated in time for the page load, there shouldn't be any measures to take. Which means that something's going wrong, and so far there's no conclusive explanation of how and why stuff fails.

And fixing results when you don't know what's wrong is like trying to hunt birds, blind-folded and with only a sling.

I also mentioned the code works on Apache, but not IIS.

You did, but that doesn't necessarily give us a clue about what's wrong, or how to fix it.

One thing you can do is to run the a client request, including image loading, both through Apache and IIS, and record the TCP streams. Then you can compare the two, and learn at which level they differ, and why the browser doesn't display the image.

Perl 6 - links to (nearly) everything that is Perl 6.
  • Comment on Re^9: Broken image link when calling CGI from img tag

Replies are listed 'Best First'.
Re^10: Broken image link when calling CGI from img tag
by lintunen (Novice) on Aug 09, 2010 at 11:54 UTC

    I had a further think about the issue and threw in a "sleep" function and as sleep allowed the page to render correctly on first load, I am guessing the issue is that the call to the piece of code that generates the image isn't completing before code execution continues.

    The piece of code that generates the image file is done by passing an input file to R:

    open($R, "|C:/Progra~1/R/R-2.11.0-x64/bin/R CMD BATCH " . $R_FILE) or +die $!; close($R);
    (This line of code was ported from Linux). I have tried a few various ways to try to make execution wait the image generation to finish but perhaps I am going about it the wrong way because nothing I have tried works or that it's a problem specific to the Windows environment. Do you have any suggestions on where to go from here?

      Since I don't see any progress, this will be my last reply in this thread.

      You won't achieve anything as long as you don't actually understand what's going on. Which is why JavaFan and I suggested you analyze the HTTP traffic. No response from your part.

      You really need to find out what the lower-level reason is for the browser not displaying any image. Is the img tag missing from the generated HTML? Does the browser attempt to load the image? What is returned? Is the content-type header for the image correct? What's the difference between the HTTP streams of the working and non-working setup?

      If you don't know how to obtain that information, re-read the thread here, there have been some pointers to tools. Or ask again. But don't simply ignore them.

      Since you haven't answered all of those questions, my only remaining advice is "find somebody who fixes it for you". You might need to pay some good money for that, but that's the tradeoff for not getting deep into the issue yourself.

        I apologise if I haven't provided the correct information, I was doing my best to provide information what I thought to be relevant. Everybody thinks about how to solve problems a little differently.

        I in fact did analyse the HTTP traffic (with Fiddler) even before I created this thread but nothing jumped out at me. I may be repeating myself here as some of the questions I have already answered but here goes... No there is nothing wrong with the generated HTML. Yes the browser attempts to load the image. What is returned - if you mean in the browser, a broken image icon until the page is refreshed (if you meant something else, please specify). Content-type is returned as text/html before the refresh but after, it is img/png. If I understand your question about the HTTP stream correctly, output from Firebug indicates there is some kind of timing problem of when the HTML is displayed and the image generation is completed. Additionally, when the image doesn't generate and I view the text output it reports a 502 error: "502 - Web server received an invalid response while acting as a gateway or proxy server" which I guess, suggests a problem with the CGI code.