duanbixia7738 2015-03-27 15:23
浏览 81
已采纳

长PHP脚本运行多次

I have a products database that synchronizes with product data ever morning.

The process is very clear:

  • Get all products from database by query
  • Loop through all products, and get and xml from the other server by product_id
  • Update data from xml
  • Log the changes to file.

If I query a low amount of items, but limiting it to 500 random products for example, everything goes fine. But when I query all products, my script SOMETIMES goes on the fritz and starts looping multiple times. Hours later I still see my log file growing and products being added.

I checked everything I could think of, for example:

  • Are variables not used twice without overwriting each other
  • Does the function call itself
  • Does it happen with a low amount of products too: no.
  • The script is called using a cronjob, are the settings ok. (Yes)

The reason that makes it especially weird is that it sometimes goes right, and sometimes it doesnt. Could this be some memory problem?

EDIT wget -q -O /dev/null http://example.eu/xxxxx/cron.php?operation=sync its in webmin called on a specific hour and minute

Code is hundreds of lines long...

Thanks

  • 写回答

4条回答 默认 最新

  • doudou1897 2015-03-31 12:46
    关注

    I solved the problem myself. Thanks for all the replies!

    My MySQL timed out, that was the problem. As soon as I added:

        ini_set('mysql.connect_timeout', 14400);
        ini_set('default_socket_timeout', 14400);
    

    to my script the problem stopped. I really hope this helps someone. Ill upvote all the locking answers, because those were very helpful!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化