1

I am developing PHP/Apache/MySQL based code on my Windows 10 laptop via Windows Subsytem For Linux.

I am working on some code that is time related. It has a mix of PHP date commands, and MySQL "NOW()" calls. I need to be able to work on this at any time, not just within the dates given in my database records.

I could set my Windows system clock and prevent it updating, but then using the Internet becomes almost impossible, as does any SSH connection as the clocks won't be in sync so secure connections won't work.

I need to time travel.

Without messing with all my data to change the end dates of thousands of records, anyone know of a simple / common way for me to have PHP and MySQL running via WSL on Windows 10, think that the date is something other than it is?

5

1 Answer 1

2

Because WSL is not a virtual machine, it's always going to be tied to your underlying system time. If modifying your system time on demand is too cumbersome, you only have two options as far as I can see.

  1. Move the running code you're testing to an actual VM where you can modify the system time.

  2. Use some sort of test framework that allows mocking calls to date related functions. How to achieve that via PHP is probably a better question for stackoverflow.com though.

2
  • Thanks - hadn't considered a VM to be honest, and now feel pretty dumb. That seems the most likely solution.
    – Hippyjim
    Jun 29, 2018 at 19:32
  • actually you have another better solution
    – phuclv
    Jul 8, 2018 at 2:13

Not the answer you're looking for? Browse other questions tagged .