Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error export book from API #3394

Closed
2 tasks done
cevinov opened this issue Apr 24, 2022 · 15 comments
Closed
2 tasks done

Error export book from API #3394

cevinov opened this issue Apr 24, 2022 · 15 comments

Comments

@cevinov
Copy link

cevinov commented Apr 24, 2022

Attempted Debugging

  • I have read the debugging page

Searched GitHub Issues

  • I have searched GitHub for the issue.

Describe the Scenario

Hello i already try to use this guide link :
https://www.reddit.com/r/BookStack/comments/razmx8/exporting_the_whole_bookstack_as_html_or_pdf_file/

But i got this error :
PHP Fatal error: Uncaught TypeError: Return value of apiGetJson() must be of the type array, null returned in /book/book-to-static.php:240
Stack trace:
#0 /book/book-to-static.php(192): apiGetJson()
#1 /book/book-to-static.php(32): getBookBySlug()
#2 {main}
thrown in /book/book-to-static.php on line 240

Footage :
https://screenrec.com/share/dSj6oqNKyr

Exact BookStack Version

PHP Fatal error: Uncaught TypeError: Return value of apiGetJson() must be of the type array, null returned in /book/book-to-static.php:240 Stack trace: #0 /book/book-to-static.php(192): apiGetJson() #1 /book/book-to-static.php(32): getBookBySlug() #2 {main} thrown in /book/book-to-static.php on line 240

Log Content

[2022-04-03 09:44:49] production.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 116640000 bytes) {"userId":1,"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 116640000 bytes) at /var/www/html/vendor/intervention/image/src/Intervention/Image/Gd/Decoder.php:128)
[stacktrace]
#0 {main}
"}
[2022-04-24 12:18:11] production.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 64448059 bytes) {"userId":1,"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 64448059 bytes) at /var/www/html/app/Entities/Tools/ExportFormatter.php:231)
[stacktrace]
#0 {main}
"}
[2022-04-24 12:18:19] production.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 65950651 bytes) {"userId":1,"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 65950651 bytes) at /var/www/html/app/Entities/Tools/ExportFormatter.php:231)
[stacktrace]
#0 {main}
"}
[2022-04-24 12:18:32] production.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 64448059 bytes) {"userId":1,"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 64448059 bytes) at /var/www/html/app/Entities/Tools/ExportFormatter.php:231)
[stacktrace]
#0 {main}
"}
[2022-04-24 12:19:00] production.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 64448059 bytes) {"userId":1,"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 64448059 bytes) at /var/www/html/app/Entities/Tools/ExportFormatter.php:231)
[stacktrace]
#0 {main}
"}
[2022-04-24 12:21:24] production.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 64448059 bytes) {"userId":1,"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 64448059 bytes) at /var/www/html/app/Entities/Tools/ExportFormatter.php:231)
[stacktrace]
#0 {main}
"}
[2022-04-24 12:23:23] production.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 64448059 bytes) {"userId":1,"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 64448059 bytes) at /var/www/html/app/Entities/Tools/ExportFormatter.php:231)
[stacktrace]
#0 {main}
"}
[2022-04-24 13:06:12] production.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 64448059 bytes) {"userId":1,"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Allowed memory size of 134217728 bytes exhausted (tried to allocate 64448059 bytes) at /var/www/html/app/Entities/Tools/ExportFormatter.php:231)
[stacktrace]
#0 {main}
"}

PHP Version

7.4

Hosting Environment

Oracle cloud
OS : Oracle linux 8.5

Bookstack install on Docker
Docker version 20.10.14

@ssddanbrown
Copy link
Member

Hi @cevinov,
The API scripts have fairly limited error handling, since they're only provided as examples.
This error can error on any issue contacting your instance over the API.

Before anything else, just a warning, your video shows your BookStack URL and API credentials. Anyone could use these details to access your instance. You might want to take this video down if this is a security concern for you.

Otherwise:

  • The $apiUrl variable at the top of the script does not look correct. This should be the base URL of your BookStack instance, not a link to a specific book (So remove the /books/c-documentation part).
  • The script expects to be ran in the following format: php book-to-static.php <book_url_slug> <output_dir>. You ran it with only passing ./book which the script would attempt to use as an identifier for the book. The first argument should be the book slug. You probably want to run it like so:
php book-to-static.php c-documentation ./book

Just keep in mind these scripts are examples for API users, More of a jumping-off point. They are not built to be 100% complete or user-friendly.

@cevinov
Copy link
Author

cevinov commented Apr 24, 2022

Hello sir, thanks for the reply. I already doing your suggestion. but i still get that error sir :
image

ad2

@ssddanbrown
Copy link
Member

It looks like it's getting further, since it's now getting to line 45 which is when page content is fetched (After other API calls), but it's hard for me to offer further support really since this could be due to a range of things.

You'd need to start check the $pages variable is as expected around line 45, and check for http request errors within the apiGetJson function. There is a dd(...); function in the script which can help dump out variables for debugging.

@cevinov
Copy link
Author

cevinov commented Apr 24, 2022

I see sir, but how to resolve this issue sir ?
image

I choose this method (PHP script) because i can't export it from the UI.

FYI I'm already do this to prevent data loss
https://www.bookstackapp.com/docs/admin/backup-restore/#files

@cevinov
Copy link
Author

cevinov commented Apr 24, 2022

and may i know how to move page without one by one sir ?. For example if i want to move 20 pages to other chapter page or book

@ssddanbrown
Copy link
Member

I see sir, but how to resolve this issue sir ?

Based upon the error logs you posted originally, It looks like you're running out of memory for PHP. This is usually configured via a memory_limit option in your php.ini file on your system.

and may i know how to move page without one by one sir ?. For example if i want to move 20 pages to other chapter page or book

Go to the parent book and use the "Sort" action. This allows you to move multiple items with relative ease.

@cevinov
Copy link
Author

cevinov commented Apr 24, 2022

Is this correct sir ? /container-bookstack/database/php

image

@ssddanbrown
Copy link
Member

@cevinov Maybe? Unfortunately I am not familiar with Oracle Linux or your setup to be sure. You can try adding a memory_limit option there to see if it makes things work, or if it changes the error message:

memory_limit = 512M

@cevinov
Copy link
Author

cevinov commented Apr 24, 2022

Hello sir, after i check on the laravel.log, the location is :
/var/www/html/app/Entities/Tools/ExportFormatter.php

And it says that i need to change memory size, but i don't see anything about that.
image

On line 231, but i don't know where do i need to put it sir ?
image

image

@ssddanbrown
Copy link
Member

@cevinov The ExportFormatter.php file is just where the memory is running out at. It's likely caused by a very large image in one of the pages which leads to hitting the memory limit at that line.
You should not be editing that PHP file.

Based upon your error log message, your PHP memory limit is still about 128MB. This may not be enough for the export to run.
This is why you need to edit the memory_limit in your php.ini file. Sometimes there might be mulitple php.ini file so you have to find the right one but this depends on your operating system and the method to run PHP and your operating system. Sometimes you might have to restart the PHP process and/or the webserver after changing any configuration for changes to take place.

@cevinov
Copy link
Author

cevinov commented Apr 24, 2022

I already try to change it sir, but it says :
image

laravel.log :

[2022-04-24 18:22:05] production.ERROR: Maximum execution time of 30 seconds exceeded {"userId":1,"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Maximum execution time of 30 seconds exceeded at /var/www/html/app/Entities/Tools/ExportFormatter.php:231)
[stacktrace]
#0 {main}
"}

Pic :
image
image

@ssddanbrown
Copy link
Member

@cevinov Well it looks like you're getting further since you're now hitting a new limit.
It looks like that max_execution_time is not taking affect if you're still getting a timeout of 30 seconds. Either you're editing the wrong file or you needs to restart processes that use that configuration (Web server/Apache).

I saw you mentioned using containers. You might need to refer to the documentation of the container that you're using to find the right way to edit the php.ini options. It's easy for changes to get lost with containers, if you are editing files within them.

@ssddanbrown
Copy link
Member

Since there's been no follow-up I'm going to close this. If the issue remains and is something you still require to be fixed respond to my previous comment and this can then be re-opened.

@cittadhammo
Copy link

cittadhammo commented Aug 18, 2024

Dear @ssddanbrown, I run into the same error when trying to export a large book with largish images.

image

I have increased the limit like mentioned:

image

and restarded the docker.

but still get the error in the laravel.lo

[2024-08-18 08:30:35] production.ERROR: Maximum execution time of 30 seconds exceeded {"userId":9,"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Maximum execution time of 30 seconds exceeded at /app/www/vendor/dompdf/dompdf/lib/Cpdf.php:5765)

@cittadhammo
Copy link

Might actually be related to timout #5119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants