0

I'm mworking on a Drupal site for which I need to export page content into PDFs. The URLs generating the pdfs are all working correctly but when I attempt to use the file_get_contents function to retrieve the page contents from http://localhost:81/export/58/pdf, it returns false indicating a failure of the function.

Similarly, I attempted using curl following examples such as this but I encounted similar issues i:e the generated pdfs where entirely empty.

I then tried a random url off the internet and I was able to get results using curl and file_get_contents.

Googling a lot, I found posts indicating allow_url_fopen needs to be ON (which it was), openssl needs to be enabled (which it was). Also, there was a post about a firewall potentially blocking things. I disabled the Windows Firewall but things still have not changed.

The potential added complication is that my Drupal site that the Drupal site is being powered from Docker. I'm not sure how that might be affecting things.

sisko
  • 9,604
  • 20
  • 67
  • 139

1 Answers1

1

It turned out my suspicions were correct, it was very much a Docker complication.

My mistake was attempting to curl localhost from within my docker container. The container can not relate to localhost or 127.0.0.1.

The solution was to find the containers internal IP address by running:

ip -4 -o address

The resulting IP address when called with curl and replacing localhost then successfully downloaded my page content, i:e :

curl http://172.20.0.7/export/export/58/pdf
sisko
  • 9,604
  • 20
  • 67
  • 139