What can make a PHP script just stop when creating a text variable?

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 ...

+6
source share
3 answers

To summarize the conversation, my main strategy was to simplify the number of software components involved in the cron call. Thus, this means moving from:

 Cron -> Lynx -> Apache -> Script 

to

 Cron -> Script 

If problems continue to manifest themselves in the new approach, then at least two components have been eliminated (and this may be faster). It appears from your comments that this has been fixed; if so, excellent.

The wider point that I repeated here is that, although a complex problem may be interesting to study, there is a point where, for cost reasons, it is best to solve the problem in another way. This may be the case, and the mystery of Lynx's failure may simply remain!

+1
source

Perhaps your problem is not related to PHP, MySQL or Apache, maybe more than in the case of the server environment, in some cases, freezing the OS and dropping cases with zombies. Have you tried such crowns in any environment other than Lynx? I mean, maybe locally or on some other server.

Have you checked the server logs for warning / error messages?

+2
source

My first step in debugging would be to extract the day variable from the $ sql generation. I don’t see anything wrong with that, so I doubt that it will accomplish much, but at least it will confirm, anyway, if it contributes to this problem.

 $day = date("l", strtotime("now")); $sql = " select fldClientName from client where fldClientId = $clientId and fldEmail{$day} = 1 "; 

You can even check the value of $day and throw a RuntimeException if it is not valid. But, as I said, I suspect that the answer lies elsewhere.

+1
source

Source: https://habr.com/ru/post/958792/


All Articles