Intercepting fopen, mysql_connect, and similar functions for migration
| From: | Kelly Jones | Date: | Sat, 09 Jun 2007 01:42:10 +0000 |
| Subject: | Intercepting fopen, mysql_connect, and similar functions for migration | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-256425@lists.php.net to get a copy of this message | ||
I'm migrating a website from one server to another, and my file paths
and dbs have changed.
For example /a/b/c/foo.txt on the old machine is at /x/y/z/foo.txt on
the new machine. The MySQL db "foo" on the old machine is "bar" on the
new machine.
Can I intercept fopen() and mysql_connect() so that when PHP does
fopen("/a/b/c/foo.txt"), I magically (using Zend functions or method
overloading or anything else) convert it at runtime to
fopen("/x/y/z/foo.txt").
Same thing so that mysql_connect("foo") becomes mysql_connect("bar").
The code is badly written: doing a search/replace in the code wouldn't
really work. I really want to "hook" fopen()/mysql_connect() and
similar commands so I can tweak their args before they actually
execute. Is there any hope?
Sort of like an LD_PRELOAD for PHP?
--
We're just a Bunch Of Regular Guys, a collective group that's trying
to understand and assimilate technology. We feel that resistance to
new ideas and technology is unwise and ultimately futile.