I have the strangest problem I have been trying to track for months. I have added lines and lines of debugging code that create log entries in a MySQL-based log, and the result does not make sense.
Basically, the script just stops. Sometimes he does it randomly, then he does it a dozen times in one place, then he can continue all the way, then he will be again next time.
More details:
Every 15 minutes I look at the list of clients, and each client has a list of data that needs to be parsed and collected for emails. If the previous version of this script is already running (i.e. there is a log entry that is less than 5 minutes), the script will not be executed again. Therefore, if I see a break in the log entries for more than a few minutes, and then another run 15 minutes after the first run, I know that something is wrong. The strangest situation from the magazine is as follows:
I logged that I was going to create a database query for client X. Then I create a variable with SQL code that contains the client ID and day of the week ( date("l", strtotime("now")) ). Then I register that the request was created successfully. Please note that the query ONLY exists in the PHP variable and has not yet been sent to MySQL!
So let me give you an example of what I see in the log:
- 3:00:00 pm - (the script starts)
- 3:00:00 pm - (it goes through customers)
- 3:00:04 pm - (he went through some clients and now works with client 20)
- 3:00:04 pm - creating a request for client 20
- (the log ends here until the script is automatically restarted after 15 minutes if there is no log entry for at least 5 minutes)
- 3:15:00 pm - (script starts)
- 3:15:00 pm - (it goes through customers)
- 3:15:04 pm - (he went through some clients, passes client 20 because he obviously had a problem, and now works on client 21)
- 3:15:04 pm - creating a request for client 21
- 3:15:04 pm - successfully created a request for client 21
- (the log ends here until the script is automatically restarted after 15 minutes if there is no log entry for at least 5 minutes)
- 3:30:00 pm - (script starts)
- 3:30:00 pm - (it goes through customers)
- 3:30:04 pm - (he went through some clients and now works with client 20)
- 3:30:04 pm - creating a request for client 20
And rinse and repeat. Now for several hours it will alternate between failures, just before it creates a request for client 20, and will fail immediately after it creates a request for client 21. Then, suddenly, it can go all the way through other clients . Then the script will run again and continue the same weird loop. And every day or so, this will happen to one or two other customers.
The request is quite simple, something like this:
$sql = " select fldClientName from client where fldClientId = $clientId and fldEmail".date("l", strtotime("now"))." = 1 ";
Basically, if it's Monday, it should check if fldEmailMonday is set to 1 to tell us that this client needs to be emailed today.
This works for a ton of our customers, but it just accidentally gets stuck with one or two customers that change day by day. And again this happens before $sql sent to MySQL! We are stuck when creating the $sql variable.
Of course, the actual query is much more complicated than what I wrote here, but $clientId and date("l", strtotime("now")) are the only variable parts in the static text.
In addition, we had the same problem for many years (I just started tracking it more now), and so far we have gone through three PHP servers and two MySQL servers - and we still have it, so we are sure that itβs not a hardware problem (e.g. memory or hard drive).
I don't know if this might be a problem, but this script is run by a cron job that runs it in lynx. This was installed before I took the code, and I do not know the reason for this. Whenever we run it manually (I usually use php index.php instead of lynx hostname://index.php ), it doesn't seem to work, ever.
So could this be a problem with Lynx? If so, why does it work in 70% of cases and does not work otherwise? Why an accident?
Or is there a problem with PHP that I have to find out? We are launching version 5.3.2 (yes, a bit outdated, but our server administrator does not want to contact her if absolutely necessary).
I assume Lynx is being used, so we get the Apache log (which, by the way, is empty, with the exception of some outdated code warnings that I'm trying to get rid of now), and I assume that if I run php index.php , I don't get the log apache Maybe there is another log file that I am missing that can help here?
In addition, it cannot be the logging code itself that calls it, because it represents only plain static text and the client identifier that is set before the SQL code is generated.
The script fails in a lot more locations, but this is the one that really makes no sense to me.
Any thoughts whatsoever about what might cause something like this?
Any thoughts on what else I can do to track it? I mean, I register myself right before and after creating the variable, and it dies between them - now make sure that I can register even more here ...