How to Get a Non-expert PDF on the Web using PHP

Asked

Viewed 59 times

0

Well, I’m trying to make use of a PDF through your link. I’m using a library called PDF Parser. The problem is that the PDF does not have a direct link. When accessing the link, a key is passed as parameter and it returns the PDF.

Here is the link: http://diario.ac.gov.br/download.php?arquivo=KEQxQHI3IyEpRE8xNDY4NjkxNjk5OTQwMi5wZGY=

In my code I’m doing:

$pdf = $parser->parseFile('http://diario.ac.gov.br/download.php?arquivo=KEQxQHI3IyEpRE8xNDY4NjkxNjk5OTQwMi5wZGY'); 

And it gives restarted connection. However, if I use a direct link to the PDF, it works normally, as follows:

$pdf = $parser->parseFile('http://cnd.fgv.br/sites/cnd.fgv.br/files/teste_2.pdf');  

How do I get this PDF?

  • Here looks normal, I managed to download the PDF without problems

  • The same here, I did a wget and it worked smoothly. (wget http://diario.ac.gov.br/download.php?arquivo=KEQxQHI3IyEpRE8xNDY4NjkxNjk5OTQwMi5wZGY= -The test.pdf)

  • @Bacco which function did you use? I try to do this within the same PHP code.

  • @Cantoni, does wget use command prompt or code itself? (I’m not very familiar with PHP)

  • I’m trying to pass the value to a variable so I can pass to the PDF Parser method.

  • The two links work the same way for me (getting programmatically). I would suggest you download the data from PHP and save it to disk for test purposes and see if the problem persists. Probably your problem is timeout. Try running PHP from the command line and see if the problem continues.

  • Yes, I got @Joãoneto. I tried it with wget on the command line just out of curiosity. How it works there, you can eliminate any mystery regarding the link itself.

  • Hmmm, I get it. Then I’ll try to see another solution. Because with the direct link it opens on time, the other link gives only restarted connection. Would it be a problem regarding the delay of the request by the server (diario.ac.Gov.br)? Because in my PHP I’ve already set the time limit to a few minutes.

  • How did you set the time limit? If you do not change the PHP config, there is no way to exceed the maximum at the time of Runtime.

  • @Bacco set_time_limit(250);

  • that there may not be respected. depending on the config, there is no way to cross the limit of php.ini

  • Hmm, so I’ll change here in php and test.

  • I put here in PHP also the maximum time and even then the connection was restarted.

  • lembdando that has the max_execution_time and also has the time limit of the web server. Generally tinkering with these things is not the correct solution. Test via command line. Even, pq if you are going to use this in practice, it pays to make a BG script to do this, without going through the web server.

  • So I think I’ll use the command line, download the pdf to the server and then open it directly. It would be better that way?

  • I meant to run PHP in BG. Anyway, first of all it is good to test if this is what it is to give qq step. If calling this PHP directly does not give the error, at least discovered the cause

  • Got it @Bacco, I’m gonna test it! Thanks!

Show 12 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.