<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jacob Santos &#187; MINIT</title>
	<atom:link href="http://jacobsantos.com/tags/minit/feed/" rel="self" type="application/rss+xml" />
	<link>http://jacobsantos.com</link>
	<description>Rumblings, rants, essays, stories by Jacob Santos about Web Site Development, Persistent Browser-Based Games, personal journal, and Programming.</description>
	<lastBuildDate>Fri, 03 Feb 2012 01:06:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3-aortic-dissection</generator>
		<item>
		<title>Loading PHP Files in a PHP Extension</title>
		<link>http://jacobsantos.com/2008/programming/loading-php-files-in-a-php-extension/</link>
		<comments>http://jacobsantos.com/2008/programming/loading-php-files-in-a-php-extension/#comments</comments>
		<pubDate>Sat, 08 Mar 2008 23:25:44 +0000</pubDate>
		<dc:creator>Jacob Santos</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[MINIT]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Extension]]></category>
		<category><![CDATA[PHP_MINIT]]></category>

		<guid isPermaLink="false">http://www.santosj.name/?p=511</guid>
		<description><![CDATA[<a href="http://jacobsantos.com/2008/programming/loading-php-files-in-a-php-extension/" title="Loading PHP Files in a PHP Extension"></a>Just so I don&#8217;t forget again. Special thanks to Johannes S. on the PHP Internals list. However, my problem is that I want to have the included PHP files with every PHP process, but only do that once. If the &#8230;<p class="read-more"><a href="http://jacobsantos.com/2008/programming/loading-php-files-in-a-php-extension/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://jacobsantos.com/2008/programming/loading-php-files-in-a-php-extension/" title="Loading PHP Files in a PHP Extension"></a><p>Just so I don&#8217;t forget again. Special thanks to Johannes S. on the PHP Internals list.</p>
<p>However, my problem is that I want to have the included PHP files with every PHP process, but only do that once. If the PHP files were in the include path, then they would still have to be included, but somehow I want the extension to include them and have them available.</p>
<h3>First Method</h3>
<p>The first method is not so much that it is impossible as it is impractical. Mostly when an extension is made, it is either a DLL or a SO file, or it is compiled into PHP. The PHP files can&#8217;t be included in the compilation, so they won&#8217;t make it in the DLL or SO or be compiled into PHP.</p>
<p>Therefore, it can be assumed in that case, that providing a relative link from C++ is impossible, because there is no way to know where the files will end up (unless you use PEAR, but even then it isn&#8217;t absolute). So you can&#8217;t just say.</p>
<pre class="brush: cpp; title: ;">
PHP_MINIT(something)
{
    // Get file handle by using zend file handle struct

    zend_execute_scripts(...); // Run in a loop to include all files.
}
</pre>
<p>Unless you could get the PHP include path (which I believe you can, but I&#8217;m unsure how) and check each of those for the files. Then however, the reason you would use PEAR is to automate everything. Somehow, the PHP files how to end up in the PEAR directory or some directory that PHP has access to or is in the include path.</p>
<h3>Second Method</h3>
<p>The second method is using PEAR to automate the process of moving the PHP files, however if the files are in the include path, then there is no need to use zend_execute_scripts().</p>
<p>In this way, if the User didn&#8217;t know about the files, they wouldn&#8217;t have to try to include them. If they don&#8217;t try to include them, then my extension can do so and during the PHP_MINIT() process.</p>
<p>So the process then becomes:</p>
<ol>
<li>Build PEAR package</li>
<li>Get PHP include Path</li>
<li>In MINIT(), Search for files and if they exist loop through zend_execute_scripts()</li>
</ol>
<h3>Best Method</h3>
<p>The best method would be to just rewrite the files as C/C++ which would increase performance better. However, it is in my opinion, that while that is the case, if you are depending on an external PHP library and want some performance, and want to only compile the scripts once per process (if the process is kept running for a long time), which might at least keep the library in memory for each PHP run after the first providing at least some advantage. If you don&#8217;t want to keep playing catchup with the external library, then the second method will work best.</p>
<p>If playing catchup every time a new release is made is no issue because of performance, then converting the PHP to C/C++ would work best. I&#8217;m of the mind, that using both methods to write the most used in C/C++ and then having the rest in PHP files is better.</p>
<p>I&#8217;m not going to write any code at this time.</p>

<p><strong>Possibly Related Posts:</strong></p>
<ul>
<li><a href="http://jacobsantos.com/2012/programming/game-engine-development-and-open-source/">Game Engine Development and Open Source</a></li>
<li><a href="http://jacobsantos.com/2011/programming/plans-for-base-cms/">Plans for Base CMS</a></li>
<li><a href="http://jacobsantos.com/2011/programming/project-plans/">Project Plans</a></li>
<li><a href="http://jacobsantos.com/2011/programming/calibre-improvements-part-2/">Calibre Improvements Part 2</a></li>
<li><a href="http://jacobsantos.com/2011/programming/usability-testing-software-development/">Usability Testing Software Development</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://jacobsantos.com/2008/programming/loading-php-files-in-a-php-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

