Umair Abid
Umair Abid

Reputation: 1463

Why Scripts Keep Running even if file doesn't exist?

I was running a script in my browser which insert like some 100000 records in database. For some reason I deleted the file in which I have written script but it was little surprising for me that the scripts keeps inserting the records in the database even when the script doesn't exist. Why is that?

Upvotes: 2

Views: 170

Answers (3)

linuxeasy
linuxeasy

Reputation: 6499

When a request is made to the web-server:

  • The PHP file is loaded into memory, it gets compiled and is running.

  • Since the file is in memory, any changes to file on disk is not applicable to running file.

If that strikes another question in you, as to "Why the hell it gets loaded into memory ?? Why can't it be executed from the disk directly ?":

  • Memory here is mostly the RAM, which is faster in doing read/write which is the need to compete with processors speed.

  • HardDisk is a slow memory and therefore, accessing from it, would make your programs very slow to execute.

To match with processors speed, there comes a need for a executable file to be loaded from Slow Memory (Often HardDisks) to a faster memory (Often Ram, or processor's cache sometimes).

And therefore, the reason and answer, as to why your file on disk is not in sync file in memory.

Also please be assured, that this would be working fine in your next request!!

But if you still want to do it immediately, you can consider stopping/restart your Apache/IIS (whichever applicable) Server, as this will kill the process immediately.

Upvotes: 2

Fania
Fania

Reputation: 353

The process is executing in memory not from disk.

If you wish to stop a running script, you will need to restart your webserver, or kill the php process. Depending on whether it was running from the command line or not.

Upvotes: 4

Bhavesh
Bhavesh

Reputation: 123

@Umair once you run the script then request go to the server and it'll run on server until process complete . so it doen't matter if file is available or not because it's old request which is under process that's why this happening.

Upvotes: 0

Related Questions