iPXE and calling PHP - Printable Version +- iPXE discussion forum (https://forum.ipxe.org) +-- Forum: iPXE user forums (/forumdisplay.php?fid=1) +--- Forum: General (/forumdisplay.php?fid=2) +--- Thread: iPXE and calling PHP (/showthread.php?tid=17482) |
iPXE and calling PHP - ndog - 2019-02-26 00:33 I'd like to be able to run a php function to write the MAC and serial to a database. This is working, however when calling the php file ipxe exits and returns to the boot selection menu or boots the hard drive (depending on machine). Ideally I'd like to boot a new computer, call a function to write serial and mac to a database (using php i presume), then be able to continue in the ipxe menu to make a different boot selection. From my testing it appears as long as php is 'ipxe compliant' and finishes running without error, it will return to ipxe menu, however because the php is running its own functions ipxe crashes with an error. menu.ipxe Code: :prestage index.php - example code 'ipxe compliant' - returns to ipxe successfully Code: <?php index.php - example code - breaks with error Code: <?php index.php - actual code works for purposes of writing database but crash exits Code: <?php Do I need to compile ipxe binary with a different option? RE: iPXE and calling PHP - NiKiZe - 2019-02-26 00:55 you call this by using kernel? any particular reason? You can use chain like you have tried, with autofree (not replace) that is a good way to do it, you just have to make sure that what is returned is actually a valid ipxe script. make sure you have echo "#!ipxe\n"; and not echo "#!ipxe \n"; (note the space) I would also recommend to skip ?>, that way anything trailing will be not be sent to the client. And of course make sure what you fetch don't contain warnings or anything else. (also what is the error you are gettings?) But with all that said what I would suggest is to use initrd instead to do the call, make sure to use --autofree RE: iPXE and calling PHP - ndog - 2019-02-27 04:36 Thanks, initrd advice was useful cheers I'm not sure half the time what I am doing, just managing to get it to work, however after testing various things with my colleague, we came to realise chain and initrd are quite different animals and managed to get a working solution using a stub php file and then calling the actual php. Not sure if its the optimal way but it works so far. menu.ipxe Code: :prestage stub.php Code: <?php index.php Code: <?php On a side note I'd prefer the params command but we didn't know how to call/test variables from it. The http://ipxe.org/cmd/params shows an example, "Issues an HTTP Post request using a form parameter list", but from the boot.php side, how does it get the values from there? RE: iPXE and calling PHP - NiKiZe - 2019-02-27 08:11 How to get values from POST requests you have to read about in the PHP documentation What do you mean about initrd and chain being different? (well yes they are, they have different purposes, but if you only want to collect parameters, then you don't need or want to chain into different script) RE: iPXE and calling PHP - ndog - 2019-02-27 20:59 Thanks for your help I am a novice and mostly learnt by experimentation than theory. initrd is different that it does not process any ipxe commands while chain will process ipxe commands, hence won't crash as far as I can tell. Regarding the php, an example would help, like the example on the params page. chain http://boot.ipxe.org/demo/boot.php##params What is a specific php documentation term I google for? |