OpenGamePanel / OGP-Website

GNU General Public License v2.0
127 stars 105 forks source link

[Windows] filemtime PHP error when no pagefile.sys exists #450

Closed SugarD-x closed 5 years ago

SugarD-x commented 5 years ago

When using the OGP web panel on Windows, the following error is triggered on Windows-based host systems that don't have a pagefile.sys file:

Warning: filemtime(): stat failed for C:\pagefile.sys in \modules\status\include\uptime.php on line 28

This occurs on the dashboard when viewing the "Webhost Status" remote server's System Uptime. The System Uptime information also becomes inaccurate because of it.

The reason behind this bug is because filemtime is unable to locate pagefile.sys on Windows systems that manage their own virtual memory. (Systems set to automatically manage it don't create the file). Systems that have the virtual memory management manually set will have a pagefile.sys file, and thus are not affected by this issue.

Edit: Apparently this is a very difficult thing to do on Windows. After some pretty extensive searching, I was able to find a method that works without needing pagefile.sys, but it requires using an executable program in addition to some PHP code. The way I did it was by using the core PHP code referenced here: http://www.bertel.de/software/uptime/php-en.html

And by placing the following file in C:\Windows\ for the PHP code to reference, (as it won't work without it): https://neosmart.net/uptime/

(Unfortunately the version of this application that Microsoft used to host themselves is no longer available on their website)

This is the default output I received on my own Windows system which was affected by the original bug, as an example: defaultuptimeoutput

own3mall commented 5 years ago

Solution is to use a pagefile.

SugarD-x commented 5 years ago

That's not a solution, though. Windows, by default, manages virtual memory itself. The only way to create a pagefile.sys file is by manually setting the virtual memory to pre-defined amounts. This can lead to undesired results on some systems.

own3mall commented 5 years ago

https://stackoverflow.com/questions/7663447/get-windows-uptime-load-with-php

There's no good solution. My advice is to use a startup script such as the following to fake it.

Save this in a file called "pagefile_cdrive.bat"

@echo off
for /F %%A in ("C:\pagefile.sys") do If %%~zA equ 0 del "C:\pagefile.sys"
IF not EXIST "C:\pagefile.sys" copy /y NUL "C:\pagefile.sys" >NUL

Add it as a startup task or script.

SugarD-x commented 5 years ago

Unfortunately it is immediately closing, stating that it cannot find C:\pagefile.sys when run. The panel's error also still exists.

own3mall commented 5 years ago

Yep, it will say that if the file doesn't exit. Then, the script creates it. And then, filemtime should be able to grab the last modified time on the file. See that the script creates C:\pagefile.sys

I tested the script on my own machine before posting it, and a C:\pagefile.sys file was created as an empty file...

SugarD-x commented 5 years ago

Yep, it will say that if the file doesn't exit. Then, the script creates it. And then, filemtime should be able to grab the last modified time on the file. See that the script creates C:\pagefile.sys

I tested the script on my own machine before posting it, and a C:\pagefile.sys file was created as an empty file...

Unfortunately it doesn't seem to work on my end. I'm still getting an error on the web panel complaining that the file isn't found.

own3mall commented 5 years ago

So find out why it's not working for you... can PHP access that file path? Not sure how you installed the OGP panel...

SugarD-x commented 5 years ago

I installed it as a normal website through IIS. PHP is able to access my C:\Windows directory, (which is where that executable from my workaround in the first post was placed), so it should have no issue accessing the core C: drive. I'm not getting any permissions errors. The server just seems to believe that the file doesn't exist at all.