问题
I'm using Joomla 2.5.8 and have a custom component installed that fetches data from the DB and generates custom PDF files using TCPDF.
Upon request by the user, the model loads a bunch of data from the DB, which is OK, there is no timeout, the request takes a few seconds and there is no more query sent to the database afterwards. Based on the data received, a processing is done to generate PDF files and the list of PDF files generated is retuned to the view to be displayed in the layout.
Everything seems to work fine and processing completes correctly but, probably due to the long processing that is done in the model, the menu module is not loading and the following error is returned:
MySQL server has gone away
SQL:
SELECT m.id, m.title, m.module, m.position, m.content,
m.showtitle, m.params, mm.menuid
FROM jos2_modules AS m LEFT JOIN
jos2_modules_menu AS mm ON mm.moduleid = m.id LEFT JOIN
jos2_extensions AS e ON e.element = m.module AND e.client_id = m.client_id
WHERE m.published = 1 AND e.enabled = 1 AND
(m.publish_up = '0000-00-00 00:00:00' OR m.publish_up <= '2013-10-31 15:42:00') AND
(m.publish_down = '0000-00-00 00:00:00' OR m.publish_down >= '2013-10-31 15:42:00') AND
m.access IN (1,1,2,3,4) AND m.client_id = 0 AND
(mm.menuid = 101 OR mm.menuid <= 0)
ORDER BY m.position, m.ordering
Note that if I remove the PDF file processing, there is no error. I have no control on the time spent in this processing but maybe I'm not doing it in the right place.
I also understand from previous posts that there are parameters in the MySQL configuration that can be tuned in MySQL ini files but this is not something I can do as the SQL server is hosted by my provider. Moreover, I'm not having access to the database when the error occurs.
Has anybody already experience that kind of problem ?
回答1:
This could be a timeout issue.
Are you running a single query which is used to create many pdf files? If so it could timeout, or the pdf file creation might be closing the query (more likely).
You should try re-running the query for each document you want to create, the overhead is minimal, if the queries are the same they will be cached.
The query you posted seems pretty fast, for all queries make sure indexes are present to keep them fast. (not a solution but could solve your problem). Finally, if the queries are in real timeout, you could create the documents one at a time and present the result with an ajax call, so your server only generates one document at a time and possibly doesn't timeout. This will also make the site appear quicker to the user.
Also you might try increasing the of the php script set_time_limit(200);
, I'm not sure if this will be effective though, and it will be a lousy user experience if they have to wait three minutes to see the page, they'll just hit reload before the timeout.
来源:https://stackoverflow.com/questions/19711830/mysql-server-has-gone-away