有时也无法加载localhost和IP

I usually use localhost to access my PHP page. But sometimes the localhost keeps loading for hours. So then I tried to access the page with 127.0.0.1, and it worked.

But a couple of days later, the 127.0.0.1 had the same problem with the localhost (keeps loading for hours), then I switched it again to localhost and it worked.

It goes vice versa all the time. What is the problem and how can I fix it?

I'm not using XAMPP nor WAMP, but I'm using raw Apache v2.2 because I have to run PHP SAPRFC function that said only works with that version of Apache.

It is probably because you have some cookie that belongs to localhost, and that cookie makes the script execute for a long time. When you started to use 127.0.0.1 instead, that cookie is not sent, so the script doesn't take long to execute.

The time 127.0.0.1 doesn't work but localhost works, maybe the cookie that makes the script execute for a long time is set again, or some entry associated with the cookie is inserted into your database, or some file associated with the cookie is changed. But the cookie that makes localhost load for a long time has expired. Therefore localhost works again.

127.0.0.1 and localhost will probably work again if you delete your cookies. But you may want to have a backup of your cookies in order to debug your script.