迁移 MySQL 数据、速度和性能效率

发布于 2024-10-19 06:49:38 字数 420 浏览 6 评论 0原文

我必须更改网络应用程序的蓝图以减少加载时间(http://stackoverflow.com/questions/5096127/best-way-to-scale-data-decrease-loading-time-make-my-webhost-happy) 。

蓝图的这种变化意味着我的应用程序的数据必须迁移到这个新的蓝图(否则我的应用程序将无法工作)。为了迁移我的所有 MySQL 记录(数千条记录),我编写了一个 PHP/MySQL 脚本。

在我的浏览器中打开此脚本不起作用。我已将脚本的时间限制设置为 0 以实现无限制的加载时间,但几分钟后脚本停止加载。 cronjob 也不是一个真正的选择:1)奇怪的是它无法加载,但最大的问题是:2)我担心这会消耗我的共享服务器的太多资源。

您知道使用此 PHP/MySQL 脚本快速有效地迁移所有 MySQL 记录的方法吗?

I had to change the blueprint of my webapplication to decrease loading time (http://stackoverflow.com/questions/5096127/best-way-to-scale-data-decrease-loading-time-make-my-webhost-happy).

This change of blueprint implies that the data of my application has to be migrated to this new blueprint (otherwise my app won't work). To migrate all my MySQL records (thousands of records), I wrote a PHP/MySQL script.

Opening this script in my browser doesn't work. I've set the time limit of the script to 0 for unlimited loading time, but after a few minutes the script stops loading. A cronjob is also not really an option: 1) strange enough it doesn't load, but the biggest problem: 2) I'm afraid this is going to cost too much resources of my shared server.

Do you know a fast and efficient way to migrate all my MySQL records, using this PHP/MySQL script?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

╰ゝ天使的微笑 2024-10-26 06:49:38

您可以尝试 PHP 的“ignore_user_abort”。这有点危险,因为您需要某种方法来结束它的执行,但您的浏览器可能会在脚本花费太长时间后中止。

You could try PHP's "ignore_user_abort". It's a little dangerous in that you need SOME way to end it's execution, but it's possible your browser is aborting after the script takes too long.

梦冥 2024-10-26 06:49:38

我解决了问题!

是的,这会花费很多时间,是的,这会导致服务器负载增加,但它只是需要完成。我在迁移时使用错误日志来检查错误。

如何?

1)我添加了 ignore_user_abort(true);set_time_limit(0); 以确保脚本在服务器上继续运行(停止当 while() 循环完成时)。

2) 在 while() 循环中,我添加了一些代码,以便能够通过创建一个名为 stop.txt 的小文本文件来停止迁移脚本:

    if(file_exists(dirname(__FILE__)."/stop.txt")) {
    error_log('Migration Stopped By User ('.date("d-m-Y H:i:s",time()).')');
    break;
}

3) 迁移错误和重复项会记录到我的错误日志中:

error_log('Migration Fail => UID: '.$uid.' - '.$email.' ('.date("d-m-Y H:i:s",time()).')');

4) 迁移完成后(使用 mail()),我会收到一封包含迁移结果的电子邮件,因此我不必手动检查。

这可能不是最好的解决方案,但它是一个很好的解决方案!

I solved the problem!

Yes, it will take a lot of time, yes, it will cause an increase in server load, but it just needs to be done. I use the errorlog to check for errors while migrating.

How?

1) I added ignore_user_abort(true); and set_time_limit(0); to make sure the scripts keeps running on te server (stops when the while() loop is completed).

2) Within the while() loop, I added some code to be able to stop the migration script by creating a small textfile called stop.txt:

    if(file_exists(dirname(__FILE__)."/stop.txt")) {
    error_log('Migration Stopped By User ('.date("d-m-Y H:i:s",time()).')');
    break;
}

3) Migration errors and duplicates are logged into my errorlog:

error_log('Migration Fail => UID: '.$uid.' - '.$email.' ('.date("d-m-Y H:i:s",time()).')');

4) Once migration is completed (using mail()), I receive an email with the result of migration, so I don't have to check this manually.

This might not be the best solution, but it's a good solution to work with!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文