admin管理员组文章数量:1332377
I´m doing a plugin which includes a query to import data from external API into custom post types/taxonomies/medias etc...
The query can be really heavy.
I had to make logs to know exactly what happens.
For the moment I´m saving logs thanks to update_option()
to avoid loose logs when I have these kinds of errors :
- 503 Service Unavailable errors
- timeout server error
- php errors etc... But, I got a new error :
mysqli_real_connect(): (HY000/2002): Connection refused
Maybe because there are too many action with the database.
I changed define('DB_HOST', 'localhost');
by define('DB_HOST', '127.0.0.1');
without any success.
If I´m using a log file, I will have to open/write/close the log file all the time and the algorithme would need more time. That could create a timeout server error.
What could be the best way in my case ?
I´m doing a plugin which includes a query to import data from external API into custom post types/taxonomies/medias etc...
The query can be really heavy.
I had to make logs to know exactly what happens.
For the moment I´m saving logs thanks to update_option()
to avoid loose logs when I have these kinds of errors :
- 503 Service Unavailable errors
- timeout server error
- php errors etc... But, I got a new error :
mysqli_real_connect(): (HY000/2002): Connection refused
Maybe because there are too many action with the database.
I changed define('DB_HOST', 'localhost');
by define('DB_HOST', '127.0.0.1');
without any success.
If I´m using a log file, I will have to open/write/close the log file all the time and the algorithme would need more time. That could create a timeout server error.
What could be the best way in my case ?
Share Improve this question edited Jul 2, 2020 at 4:39 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Jul 1, 2020 at 23:23 J.BizMaiJ.BizMai 9002 gold badges10 silver badges30 bronze badges1 Answer
Reset to default 0I'd recommend doing large bulk updates to the database like big imports or exports outside of the Wordpress codebase as much as possible because of issues like this, but only if this makes sense for your code and you're able to maintain the wordpress data structures
If the logging information is just to see what happens with this operation and you don't need it after or to see it in Wordpress, then update_option
is definitely not a great solution. Opening a file, or writing to your own table would be better.
There's no reason not to write a PHP script which opens a single connection to the database to do its work, a single file for logging and does what it needs to do.
Or, if you want to take advantage of some Wordpress calls, then use wp-cli's eval-file to run a script which will give you access to those.
For tasks like this if you don't already have it then access to the command line, e.g. through ssh will make your life a lot easier and save you tons of time. This approach may also give you much easier access to error messages.
For more help with the specific thing you're doing more details on the heavy query you're running would help. Connection refused and those other errors could be caused by a lot of things, but your approach of having logging somewhere is a good one, as long as it helps to diagnose problems and retry the rest of the work.
本文标签: performanceWritesaved logs in Wordpress
版权声明:本文标题:performance - Writesaved logs in Wordpress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742295153a2448573.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论