More problems with pdf / mysql 
Author Message
 More problems with pdf / mysql

Hi again,
          I asked yesterday about storing pdf files in mysql. I wasn't
doing anything obviously wrong so I worked through things slowly. What
I'm trying to do is implement a report building daemon with a queue
(these reports can take 5-10 mins to build). I've found that I'm getting
the pdf inserted and retrieved correctly, the problem is in the viewer.
The following script is called via javascript window.open from the queue
window when the daemon has completed the pdf.

The three commented lines cause all the problem. The purpose of that
statement is to remove the report from the queue once it has been
displayed. Without those lines this works fine and displays the pdf
file. With them I simply get a blank page in the browser. There is no
error message, I checked.

WHY? Is it a bug?

<?php include('electricity.lib');

       $query = "select * from reportqueue ".
                "where owner=\"".$user['realName']."\" ".
                "and started=\"$started\" ";
       $result = mysql_query($query);
       $r = mysql_fetch_assoc($result);
       $content = $r['content'];

#     mysql_query("delete from reportqueue ".
#                 "where owner=\"".$user['realName']."\" ".
#                 "and started=\"$started\" ");

       header('Content-Type: application/pdf');
       echo $content;

?>

TIA
Kevin Thorpe
Head of IT
Purchasing Index (UK) Ltd



Sun, 26 Jun 2005 18:46:48 GMT  
 More problems with pdf / mysql

Quote:

> #     mysql_query("delete from reportqueue ".
> #                 "where owner=\"".$user['realName']."\" ".
> #                 "and started=\"$started\" ");

My guess:
http://www.php.net/manual/en/function.mysql-query.php
"The optional result_mode parameter can be MYSQL_USE_RESULT and
MYSQL_STORE_RESULT. It defaults to MYSQL_STORE_RESULT, so the result is
buffered. See also mysql_unbuffered_query() for the counterpart of this
behaviour."

Thus it is possible (though probably unlikely) that you're deleting the
object before your app actually gets to render the whole thing.

Try mysql_unbuffered_query() for fetching the PDF data.

Another possibility is that mysql_query() is generating some output, thus
hosing your header(). Try the query without the header() part and see if it
generates any output.

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.



Sun, 26 Jun 2005 18:56:29 GMT  
 More problems with pdf / mysql

Quote:
> Thus it is possible (though probably unlikely) that you're deleting the
> object before your app actually gets to render the whole thing.

> Try mysql_unbuffered_query() for fetching the PDF data.

That sounds very plausible. If I have 5 reports ready in the queue I get
a mix of correct contents and zero length contents. Changing the delete
to an update works fine, but not what I want.

I am explicitly extracting $contents from the row set to avoid exactly
this problem. IIRC php copies variables not rereference them. Maybe it
does it lazily, only requiring the copy to be complete on the next use
of the variable. By that time the rowset might be destroyed.

Oddly though, strlen($content) is zero before I execute the delete
statement. Something is happening in parallel here and I don't know
what.

I tried mysql_unbuffered_query and it didn't help.

regards
Kevin Thorpe



Sun, 26 Jun 2005 19:32:38 GMT  
 More problems with pdf / mysql

Quote:

> IIRC php copies variables not rereference them.

That's correct, unless you explitely create a reference:
$foo =& $bar;

Quote:
> Maybe it
> does it lazily, only requiring the copy to be complete on the next use
> of the variable. By that time the rowset might be destroyed.

That was my thought as well.

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.



Sun, 26 Jun 2005 19:46:38 GMT  
 More problems with pdf / mysql
Awwwww poo!

Sorry for wasting time here. I found out eventually that the app
generating the sql records wasn't creating unique ids (and the moron
that specced the table [me!] didn't enforce it). Hence generating the
first report was deleting other ones as well.

What a complete plonker!

thanks anyway.
Kevin Thorpe



Sun, 26 Jun 2005 20:25:19 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. How do I store pdf files in mysql?

2. Search some String in PDF with PDF.OCX

3. Appendix.pdf - Appendix.pdf (0/6)

4. extract info from pdf doc,PDF to XML, HTML

5. CL-PDF the Common Lisp PDF Library 0.2

6. CL-PDF: need beta testers for cl-pdf 1.0

7. CL-PDF 0.45 (The Common Lisp PDF Library)

8. CL-PDF 0.41 (The Common Lisp PDF Library)

9. CL-PDF (Common Lisp PDF library) beta test

10. CL-PDF 0.3 (The Common Lisp PDF Library)

11. Acrobat 3.0 PDF Version of Tcl/Tk 8.0 Quick Reference - refbase.pdf (1/1)

12. Acrobat 3.0 PDF Version of Tcl/Tk 8.0 Quick Reference - refbase.pdf (0/1)

 

 
Powered by phpBB® Forum Software