• Hello,

    i am developing a plugin for WordPress. I my Plugin i can choose an PDF which is uploaded to WordPress. If i have choose a PDF file i can click on the “start import” button and then ajax call a php function which read the file and save every page as .jpg.I use ImageMagick. Everthing is working fine. But if i take a PDF with 50 MB the ajax call nerver ends. Does any one have a idea?

    At first i thought maybe its the max_execution time or something elese but it doesn’t.

    Sometimes the script generate the Pages 1-30 and after that the ajax call start from the beginning and then the script generate all 50 pages, but the ajax call become no response. I get no 200 or 404 i got nothing. But this is only in the big PDF’s.

    Has WordPress any ajax timeout or something like that?

    Thanks for the help.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Moderator bcworkz

    (@bcworkz)

    There’s a PHP script temeout that applies to any request, AJAX or not. It usually defaults to 30 sec., but can usually be altered with ini_set(). If not, it has to be set in php.ini.

    There’s also a script memory limit that can be exceeded when processing large amounts of data. Additionally, there is a max. file upload size (“upload_max_filesize”), which I think is what you are running up against since the file size limit is a nice even number.

    These limits should also be able to be overridden with ini_set(). Again, if that does not work, the change needs to be in php.ini. php.ini changes normally require a server restart to take effect. If you are on shared hosting and ini_set() does not work, check with your host about upping the limit.

    Thread Starter lecom24

    (@lecom24)

    Thanks for the anserwer. Here are my specifications for my localhost:

    max_execution_time = 3000
    memory_limit = 8G
    upload_max_filesize = 100M

    I think normaly that’s enought or?

    Your missing:
    post_max_size = 32M

    and if you do not want to edit php.ini, the only way to do this with big files is to upload before the file, maybe chunking it, so processing on server and removing, after the conversion process has been completed?

    Thread Starter lecom24

    (@lecom24)

    @potentdevelopment
    post_max_size = 100M

    @axew3
    befor the script converting each site as .jpg the PDF file is uploaded to the wordpress media files. The upload is no problem. Only the converting process.

    Thread Starter lecom24

    (@lecom24)

    I have checked the script with xdebug. Now i can see. At the end of the PHP Script there is an wp_die(); this one start the script from the beginning. Anyone know why?

    Moderator bcworkz

    (@bcworkz)

    That is normal for AJAX handlers because once the response is sent out the AJAX request has completed and there is nothing left to do. The continuation of a process needs to be handled elsewhere, either in the originating jQuery, or within a PHP loop prior to wp_die(). Failure to terminate an AJAX request will leave process threads open, eventually crashing the server.

    Thread Starter lecom24

    (@lecom24)

    @bcworkz
    Thanks for the answer. The problem is fixed. But now i get in Chrome as Statuscode 200 but in Firefox nothing. Do you have an idea?

    Moderator bcworkz

    (@bcworkz)

    The server should be responding the same way regardless of your browser, I imagine Chrome is being more helpful while FF remains quiet since 200 means all is fine. Depending on what you’re looking at, this may be fine or very odd. I think there is not much to worry about as long as the server is responding correctly.

    Thread Starter lecom24

    (@lecom24)

    Okay Thanks for the anwsers

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Ajax call in plugin’ is closed to new replies.