The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 807 - File: showthread.php PHP 7.3.15 (Linux)
File Line Function
/showthread.php 807 errorHandler->error





Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
iPXE PHP LOOPs not working
2014-07-04, 13:30 (This post was last modified: 2014-07-04 13:35 by jhonny.)
Post: #1
iPXE PHP LOOPs not working
Hi Guys,

I'm trying to get a php loop going ...

To save some time, i'll just describe the beginning of the script:
- server boots php script which determines its serial number (serversn)
- it connects to the database and checks if the server is there and what its (job) value is.
- if the server isn't in the database it is added to it with a default job value of 00

then the following script is where I'm having issues:

Code:
        do
        {
        print "echo Job 00 found, looping through ..."."\n";
        $result = mysqli_query($con,"SELECT * FROM servers WHERE sn='$serversn'");    //pull out details of the server
            while($row = mysqli_fetch_array($result))                //loop to pull out all rows from the database
            {
            $serial=$row['sn'];                            //grab server serial number
            $desc=$row['model'];                            //grab server model
            $job=$row['job'];                            //grab server job
            print "echo Current value of serial = ".$serial."\n";
            print "echo Current value of job = ".$job."\n";
            print "sleep 10"."\n";
            }        
        } while ($job==00);

        if ($job==01)
        {
        print "echo Job 01 found, HELLO"."\n";
        print "sleep 5"."\n";
        }

What happens is when i chain load the the script using http, it loads but says:
Code:
http://192.168.0.1/test2.php?serversn=VMware-56blabla... 100%
then it goes to
Code:
http://192.168.0.1/test2.php?serversn=VMware-56blabla... 99%
then again to:
Code:
http://192.168.0.1/test2.php?serversn=VMware-56blabla... 100%

It keeps going like that for a while, approx 60 seconds, then the script actually executes and the output is as follows:

Code:
Job 00 found, looping through ...
Current value of serial = VMware-56
Current value of job = 00
Job 00 found, looping through ...
Job 00 found, looping through ...
Current value of serial = VMware-56
Current value of job = 00
Job 00 found, looping through ...
Current value of serial = VMware-56
Current value of job = 00

However, while the code is actually running and producing results, it is NOT connecting to the database. So when i go to the database and update the value of JOB to 01, the output is still:

Code:
Job 00 found, looping through ...
Current value of serial = VMware-56
Current value of job = 00

What is happening is while the code is stuck at loading 99%, 100%, 99% its actually connecting to the database then and pulling out results multiple times.

Does anyone know how to fix this ?
Why are the results being pulled from the database before the php script has a chance to run ?
Why isn't the database contacted while the script is executing like it should ?
What's even more interesting is while the code is stuck at 99% 100% 99%
and i go to the database and change the job value to 01 from 00, the code executes immediately, but the results are still INCORRECT, they are still being displayed for job 00 rather than job 01

Code:
Job 00 found, looping through ...
Current value of serial = VMware-56
Current value of job = 00
Job 00 found, looping through ...
Job 00 found, looping through ...
Current value of serial = VMware-56
Current value of job = 00
Job 00 found, looping through ...
Current value of serial = VMware-56
Current value of job = 00

If however, the job in the database is already 01 and the script is executed, the correct output is produced:

Code:
Job 01 found, HELLO

This is absolutely doing my head in.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
iPXE PHP LOOPs not working - jhonny - 2014-07-04 13:30



User(s) browsing this thread: 1 Guest(s)