note 42337 added to class.com

From: Date: Wed, 12 May 2004 15:23:37 +0000
Subject: note 42337 added to class.com
Groups: php.notes 
Request: Send a blank email to php-notes+get-69527@lists.php.net to get a copy of this message
"Keeping an instance of a Server object loaded" When dealing with COM objects like 'Word' or 'Excel' you are pretty much dealing with personal COM type objects. The reason I say this is because they in no way have any direct relationship to a real COM server object. The differences between a 'Server COM Object' and a 'Personal COM Type Object' are great. Server COM objects, do not contain and properties or methods related to any type of program dialog. Most Enterprise COM objects are designed to run under IIS where they are loaded into the server process. So once the first instance call is made or when the server is started the object loads it properties, methods and data related to the service the object provides! Many objects load large data set(s) 10 MB to 200 MB into memory, this makes any process after the initial loading of the object fast and very system friendly! In PHP, when an initial instance of an object is loaded some where in a PHP script, PHP will check if an instance of the object is already running if it is, then it will use that instance. If it can not find an instance to the object running, it will create a new instance to the object! In the case of personal COM type objects, you can point to a running instance of an object, and reference that instance... <? $obj = new COM ( 'X:\reports\june.doc' ); ?> For Server type COM objects that load large data set(s), you really have no option because each script run will unload the instance at the end of the script's run time. Unless another http request is running and the new http request can access the other object instance, you will have to load all the objects properties and methods and data set(s) used by the object! One way to work around this is to write a wrapper that can load the object into the PHP or the Server process! I did this for the objects I use. Another unorthodox way is to load your web browser to a PHP script that uses a combination of ignore_user_abort(), set_time_limit(), load the object, sleep();! Before I wrote the wrapper for a 'Map Server Object' I use in one of my project. I used the 'unorthodox way' for almost a year and had over 15,000 object requests a day, and never did the instance of the object ever have to start a new instance, ie: reload all the properties and methods and data set(s) used by the object! Like I said this is a very 'unorthodox way' to keep an object loaded, but it works! set the object 'My.Object' in the script, call the script from the browser, then close the browser! <? ignore_user_abort ( 'true' ); set_time_limit ( 0 ); com_load_typelib ( 'My.Object' ) or die ( 'Could not load TypeLib' ); $obj = new COM ( 'My.Object' ) or die ( 'Could not load object' ); $obj = null; sleep ( 63166608000 ); // one year ?> John ---- Manual Page -- http://www.php.net/manual/en/class.com.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42337 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42337&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42337&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69527) next »