0

I have a simple learning website for myself that parses source code from other websites. The problem is that sometimes there is an error while reading the source through file_get_contents(). That is fine but somehow the php script starts over after this error occurs. So the more errors occur the more concurrent "threads" are created and executed.

The php script is here: http://pastebin.com/vKZe6cCC

The leaderboeard_parser include: http://pastebin.com/WMd5aWGB

This is the expected output:

30.10.2014 12:55:17   Uploading test statistics ...
    30.10.2014 12:55:17: - hardcore season uploaded. Errors: 1
    30.10.2014 12:55:17: - hardcore non-season uploaded. Errors: 1
    30.10.2014 12:55:17: - softcore season uploaded. Errors: 2
    30.10.2014 12:55:17: - softcore non-season uploaded. Errors: 0
Uploading of US statistics done.

This is the usual unexpected output:

30.10.2014 12:55:17   Uploading test statistics ...
        30.10.2014 12:55:17: - hardcore season uploaded. Errors: 1
        30.10.2014 12:55:48   Uploading test statistics ...
        30.10.2014 12:55:17: - hardcore non-season uploaded. Errors: 1
        30.10.2014 12:55:48: - hardcore season uploaded. Errors: 0
        30.10.2014 12:55:17: - softcore season uploaded. Errors: 2
30.10.2014 12:56:18   Uploading test statistics ...
        30.10.2014 12:55:48: - hardcore non-season uploaded. Errors: 1
        30.10.2014 12:55:17: - softcore non-season uploaded. Errors: 0
        Uploading of test statistics done.
        30.10.2014 12:55:48: - softcore season uploaded. Errors: 1
        30.10.2014 12:56:18: - hardcore season uploaded. Errors: 2
30.10.2014 12:56:48   Uploading test statistics ...
        30.10.2014 12:55:48: - softcore non-season uploaded. Errors: 0
        Uploading of test statistics done.
        30.10.2014 12:56:18: - hardcore non-season uploaded. Errors: 0
        30.10.2014 12:56:48: - hardcore season uploaded. Errors: 0
        30.10.2014 12:56:18: - softcore season uploaded. Errors: 0
        30.10.2014 12:56:48: - hardcore non-season uploaded. Errors: 0
        30.10.2014 12:56:18: - softcore non-season uploaded. Errors: 0
        Uploading of test statistics done.
30.10.2014 12:57:19   Uploading test statistics ...
        30.10.2014 12:56:48: - softcore season uploaded. Errors: 0
        30.10.2014 12:57:19: - hardcore season uploaded. Errors: 0
        30.10.2014 12:56:48: - softcore non-season uploaded. Errors: 1
        Uploading of test statistics done.
        30.10.2014 12:57:19: - hardcore non-season uploaded. Errors: 0
30.10.2014 12:57:50   Uploading test statistics ...
        30.10.2014 12:57:19: - softcore season uploaded. Errors: 0
        30.10.2014 12:57:50: - hardcore season uploaded. Errors: 1
        30.10.2014 12:57:19: - softcore non-season uploaded. Errors: 1
        Uploading of test statistics done.
        30.10.2014 12:57:50: - hardcore non-season uploaded. Errors: 0
        30.10.2014 12:57:50: - softcore season uploaded. Errors: 1
        30.10.2014 12:57:50: - softcore non-season uploaded. Errors: 0
        Uploading of test statistics done.

Another output (the script ran for 39 minutes, just how ?): pastebin.com/AnNJMvfL

As you can see it seems like multiple instances of the script run concurrently and I have no idea why this occurs. Also this runs on free hosting server.

Also found on a forum that ftp clients can sometimes overwrite files incorrectly so i created new files (source, log) but without change.

If anyone could help me or at least suggest something that could be wrong it would be awesome.

Thank you again.

edit: I have tried it on a different server and it works how it is supposed to work. What could it be then? What sort of setting could cause this repeating?

underko
  • 1
  • 2
  • What does "leaderboard_parser.php" contain? – Ronni Egeriis Persson Oct 30 '14 at 14:17
  • Sorry, I forgot to include it: http://pastebin.com/WMd5aWGB – underko Oct 30 '14 at 14:34
  • If there is an issue with reading the source with `file_get_contents`, you'll never get out of the `while` loop. – ʰᵈˑ Oct 30 '14 at 17:07
  • Have you tried any debugging yet? Have a look at [this question on how to debug PHP code](http://stackoverflow.com/questions/888/how-do-you-debug-php-scripts). – i alarmed alien Oct 30 '14 at 17:13
  • @hd Yes, but as you can see from output it always eventually manages to download the source and parse it so it exits the loop and finishes the script correctly. Also I've tried putting limit on the errors so it break the cycles is it reaches for instance 5 errors, but it didn't help with the script repeating itself. – underko Oct 30 '14 at 17:15
  • Did you try to run the script on your local machine or a different environment? – Ronni Egeriis Persson Oct 30 '14 at 17:35
  • Ok. I have just tried it on different server and it seems to work perfectly. But that raises question what is different? They should provide similar environment no? Could it be some php setting? – underko Oct 30 '14 at 21:51
  • Check `php -i` (or `phpinfo()` ) on both servers to see if the versions of PHP are the same. – i alarmed alien Oct 30 '14 at 21:59
  • php on working server: PHP 5.3.10 not working server: PHP 5.4.26 – underko Oct 30 '14 at 22:20

0 Answers0