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条)

报告相同问题?