Hello
I was wondering if there is some construct in PHP that will allow me to know that the script has finished running.
I would like to perform some cleanup code as soon as the script finishes running. e.g. database flushing.
I know that I can invoke my code at the very end of my script but I am looking for a more robust solution.
If I depend on programmers to remember to include some code at the end of their scripts I bound to have 80% of them forgetting to do it.
I am looking for a construct similar to a desctructor.
I am using PHP 5.0
any insight would be appreciated
an indication that a script finished running
Moderator: General Moderators
Re: an indication that a script finished running
Simple enough - make their script not run without including it.jasongr wrote: If I depend on programmers to remember to include some code at the end of their scripts I bound to have 80% of them forgetting to do it.
As a header, put a ob_start() in, (say, to do utf-8 encoding, or compression, or similar).
Then in the ("required") footer, put the closing ob_end_flush.
That way, if they dont include the footer, THEY GET NO OUTPUT - obviously an error in their code.
If you find some numbskull using his OWN ob_end_flush, make him stop - should be the exception to the rule, not the rule itself.
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
Re: an indication that a script finished running
what about http://be2.php.net/manual/en/ini.sect.d ... ppend-file ?jasongr wrote: I know that I can invoke my code at the very end of my script but I am looking for a more robust solution.
If I depend on programmers to remember to include some code at the end of their scripts I bound to have 80% of them forgetting to do it.
I wonder if I can count on the destructor.
For example, I have 2 classes:
class DatabaseManagaer which provides an API for interating with the database and class A which uses it
I want class A to do some cleanup code.
can I count that the DatabaeManager object will still be alive when the destructor of class A is invoked?
For example, I have 2 classes:
class DatabaseManagaer which provides an API for interating with the database and class A which uses it
I want class A to do some cleanup code.
can I count that the DatabaeManager object will still be alive when the destructor of class A is invoked?
from the manual:
PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++. The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed.
So, if you have a reference to a databasemgr instance in your class A, it will still exist when the destructor of A is called.
PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++. The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed.
So, if you have a reference to a databasemgr instance in your class A, it will still exist when the destructor of A is called.