<?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>blog.humaneguitarist.org &#187; PHP</title>
	<atom:link href="http://blog.humaneguitarist.org/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.humaneguitarist.org</link>
	<description>discoveries in digital audio, music notation, and information encoding</description>
	<lastBuildDate>Tue, 07 Feb 2012 03:33:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>making a DOT graph for PHP include statements</title>
		<link>http://blog.humaneguitarist.org/2011/07/30/making-a-dot-graph-for-php-include-statements/</link>
		<comments>http://blog.humaneguitarist.org/2011/07/30/making-a-dot-graph-for-php-include-statements/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 17:03:02 +0000</pubDate>
		<dc:creator>nitin</dc:creator>
				<category><![CDATA[scripts]]></category>
		<category><![CDATA[technophilia]]></category>
		<category><![CDATA[DOT]]></category>
		<category><![CDATA[Graphviz]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[sinuses]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://blog.humaneguitarist.org/?p=2960</guid>
		<description><![CDATA[A couple of months ago, I posted about my experience with making a Python dependency graph. Of course, as the post states, I was originally looking for a way to make a graph showing the relationship among PHP files in regard to include statements. Well, I&#39;m home sick and after a few hours of trying [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of months ago, I <a href="http://blog.humaneguitarist.org/2011/05/07/making-my-first-dependency-graph/">posted</a> about my experience with making a Python dependency graph.</p>
<p>Of course, as the post states, I was originally looking for a way to make a graph showing the relationship among PHP files in regard to <code>include</code> statements.</p>
<p>Well, I&#39;m home sick and after a few hours of trying to find an easy, out-of-box solution I gave up and rolled my own Python script to make me a <a href="http://en.wikipedia.org/wiki/DOT_language">DOT</a> graph file.</p>
<p>I didn&#39;t have anything better to do.</p>
<p><img alt=":(" src="http://blog.humaneguitarist.org/wp-content/plugins/fckeditor-for-wordpress-plugin/ckeditor/plugins/smiley/images/sad_smile.gif" title=":(" /></p>
<p>The results are pretty simplistic, but I&#39;m happy enough with it for now.</p>
<p>The Python script takes three arguments: the directory in which the PHP files exist, whether to search recursively or not (0=no, 1=yes), and the name of the output file as such:</p>
<p><code>$ python makeDOT.py blog/wordpress 1 wordpressIncludes.dot<br />
	</code></p>
<pre class="brush:python">#####
#importing modules
import glob, re, sys, os, fnmatch
br = &quot;\n&quot;
tab = &quot;\t&quot;

#####
#exiting if all 3 arguments are not passed via command line
def fail():
    print (&quot;ERROR: &quot; + str(len(sys.argv)-1) + &quot; of 3 required arguments provided.&quot;)
    sys.exit()

#####
#getting arguments passed via command line

#testing for root DIRECTORY string
try: myDir = sys.argv[1]
except: fail()

#testing for RECURSION boolean
try: myRec = sys.argv[2]
except: fail()

#testing for OUTPUT filename string
try: myFile = sys.argv[3]
except: fail()

#####
#making list of PHP files within DIRECTORY
if myRec == &quot;0&quot;: #without recursion
    myDir2 = myDir + &quot;/*.php&quot;
    PHP_list = glob.glob(myDir2)
elif myRec == &quot;1&quot;: #with recursion
    PHP_list = []
    for dirname, dirnames, filenames in os.walk(myDir):
        for filename in filenames:
            if fnmatch.fnmatch (filename,(&quot;*.php&quot;)):
                match = os.path.join(dirname,filename)
                PHP_list.append(match)

#make an empty list;
#tuples will go in the list;
#each tuple will contain a PHP filename and a PHP filename it includes
includeList = []

#iterate through each PHP file and place tuples in the list
for phpFile in PHP_list:
    fileOpen = open(phpFile, &quot;r&quot;)
    #for each line in a PHP file
    for line in fileOpen:
            m = re.match(r&quot;(.*)include(.*\()(.*)\)&quot;, line) #for include(),include_once()
            if m:
                matchFile = m.group(3)[1:-1]
                if matchFile[-4::] == &quot;.php&quot;: #only PHP files
                    phpFile = phpFile.replace(&quot;\\&quot;,&quot;/&quot;)
                    matchFile = matchFile.replace(&quot;\\&quot;,&quot;/&quot;)
                    matchFile = matchFile.replace(&quot;\&quot;&quot;,&quot;&quot;)
                    matchFile = matchFile.replace(&#39;\&#39;&#39;,&quot;&quot;)
                    includeList.append([phpFile[len(myDir)+1:], matchFile])
            else: pass

            m = re.match(r&#39;(.*)require(.*\()(.*)\)&#39;, line) #for require(), require_once()
            if m:
                matchFile = m.group(3)[1:-1]
                if matchFile[-4::] == &#39;.php&#39;: #only PHP files
                    phpFile = phpFile.replace(&quot;\\&quot;,&quot;/&quot;)
                    matchFile = matchFile.replace(&quot;\\&quot;,&quot;/&quot;)
                    matchFile = matchFile.replace(&quot;\&quot;&quot;,&quot;&quot;)
                    matchFile = matchFile.replace(&#39;\&#39;&#39;,&quot;&quot;)
                    includeList.append([phpFile[len(myDir)+1:], matchFile])
            else: pass

#####
#creating DOT file
dot = open(myFile, &quot;w&quot;)

#writing to DOT file
dot.write(&quot;digraph {&quot; + br)
for a,b in includeList:
    dot.write(tab)
    dot.write(&quot;\&quot;&quot;)
    dot.write(a)
    dot.write(&quot;\&quot;&quot;)
    dot.write(&quot; -&gt; &quot;)
    dot.write(&quot;\&quot;&quot;)
    dot.write(b)
    dot.write(&quot;\&quot;&quot;)
    dot.write(&quot;;&quot;)
    dot.write(br)
dot.write(&quot;}&quot;)
dot.close()

#####
#exiting
sys.exit()
</pre>
<p>I ran the Python script on the PHP scripts for <a href="http://blog.humaneguitarist.org/projects/mxmliszt/">MXMLiszt</a>.</p>
<p>Then I used the &quot;circo&quot; layout engine in <a href="http://en.wikipedia.org/wiki/Graphviz">Graphviz</a> &#8211; specifically the Gvedit.exe application &#8211; on <a href="http://blog.humaneguitarist.org/uploads/MXMLisztIncludeGraph.dot.txt">this</a> resultant DOT file.</p>
<p>Here&#39;s the result:</p>
<p><a href="http://blog.humaneguitarist.org/uploads/MXMLisztIncludeGraph.gif"><img alt="" height="303" src="http://blog.humaneguitarist.org/uploads/MXMLisztIncludeGraph.gif" width="320" /></a><a href="http://blog.humaneguitarist.org/uploads/MXMLisztIncludeGraph.gif"><br />
	</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.humaneguitarist.org/2011/07/30/making-a-dot-graph-for-php-include-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>running XQuery online</title>
		<link>http://blog.humaneguitarist.org/2009/11/08/running-xquery-online/</link>
		<comments>http://blog.humaneguitarist.org/2009/11/08/running-xquery-online/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 01:26:54 +0000</pubDate>
		<dc:creator>nitin</dc:creator>
				<category><![CDATA[scripts]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Saxon]]></category>
		<category><![CDATA[XQuery]]></category>

		<guid isPermaLink="false">http://blog.humaneguitarist.org/?p=450</guid>
		<description><![CDATA[A while ago, I&#160;posted about my first experience with XQuery and how I&#39;d used the .NET version of the Saxon processor on my local Windows machine. Obviously, I&#160;want to extend that experience to running XQueries online. So far, I&#160;know this can easily be done with a native XML database server like eXist. That is to [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago, I&nbsp;posted about my <a href="http://blog.humaneguitarist.org/?p=152">first experience with XQuery</a> and how I&#39;d used the .NET version of the <a href="http://saxon.sourceforge.net/">Saxon</a> processor on my local Windows machine.</p>
<p>Obviously, I&nbsp;want to extend that experience to running XQueries online. So far, I&nbsp;know this can easily be done with a native XML database server like <a href="http://exist-db.org/">eXist</a>. That is to say, when I installed eXist on my local machine and made it go live: bam! &#8211; instant XML server with built-in XQuery functionality, accessible from anywhere.</p>
<p>Another way is to use one of the more popular web-scripting languages to execute XQuery syntax. I nearly killed myself this weekend trying to install the <a href="http://www.ibm.com/developerworks/opensource/library/x-zorba/index.html">Zorba PHP binding for XQuery</a> (i.e. run XQuery natively from within a PHP&nbsp;script). I just couldn&#39;t get all the dependencies successfully installed on my virtual install of <a href="http://www.ubuntu.com/getubuntu/download-netbook?info=EXLINK">Ubuntu Netbook Remix</a> (BTW: I&nbsp;use Sun&#39;s <a href="http://www.virtualbox.org/">VirtualBox</a> for virtualization). Perhaps I&#39;ll be able to make it work another time.</p>
<p>Now, even though it makes all the sense in the world to stick with a native XML server like eXist if I want to make a large collection of searchable XML documents online (and I&nbsp;do), I&#39;m feeling non-sensical. What I&nbsp;decided to try was to run my computer as a more traditional server using the X-Apache-MySql-PHP model, specifically <a href="http://www.wampserver.com/en/">WampServer</a>.</p>
<p>From there, I&nbsp;placed my sample document, &quot;<a href="http://www.w3schools.com/XQuery/books.xml">books.xml</a>&quot; and my &quot;test.xquery&quot; file from last time:</p>
<pre class="brush:xml">&lt;ul&gt;
{
for $x in doc(&quot;books.xml&quot;)/bookstore/book/title
order by $x
return &lt;li&gt;{data($x)}&lt;/li&gt;
}
&lt;/ul&gt;</pre>
<p>in WAMP&#39;s &quot;www&quot; directory &#8211; i.e. the directory which is accessible from the browser, the place where one would put all their HTML files, etc. for the world to see.</p>
<p>Of course, I was still missing the actual XQuery processor at this point. What I tried is to put the relevant executables for Saxon in the &quot;www&quot; directory as well.</p>
<p>&#8230; Now, I&#39;m sure this is totally unsafe or something, but I was just testing and I only make my computer &quot;go live&quot;&nbsp;as a server for short periods of time.</p>
<p>Anyway, from there I&nbsp;used PHP to call the Saxon processor and to display the results in the browser. It actually worked!</p>
<p>Here&#39;s the code:</p>
<pre class="brush:php">&lt;?php
echo &quot;Hi. I&#39;m going to use XQuery to list the books alphabetically.&quot;;
exec(&quot;query.exe test.xquery !indent=yes&quot;, $results);
foreach ($results as $value)
    {
       echo &quot;$value&quot;;
    }
?&gt; </pre>
<p>You can see that the PHP &quot;exec&quot; command called the Saxon executable named &quot;query.exe&quot; and executes the &quot;test.xquery&quot; file.</p>
<p>It saves the results in a variable called &quot;results&quot; and then prints each value of the results in the browser.</p>
<p>For now, I&#39;m OK with this, but I need to eventually do the same thing with the Java version of Saxon, I&nbsp;suppose, if I&#39;m ever going to run this on a Linux server. It shouldn&#39;t present any new hurdles, but I need to try it to make sure, of course.</p>
<p>If anyone out there has any thoughts or recommendations on a more elegant method to achieve these results &#8211; and what the security risks of the approach I&#39;ve outlined presents (since I didn&#39;t use a CGI-bin), please speak up. I&#39;m all ears.</p>
<p><img alt=":)" src="http://blog.humaneguitarist.org/wp-content/plugins/fckeditor-for-wordpress-plugin/ckeditor/plugins/smiley/images/regular_smile.gif" title=":)" /></p>
<p>&#8230;</p>
<p><strong>Update, November, 2009:</strong> No problems with using the Java version of Saxon. I&nbsp;did place it in a &quot;bin&quot; directory on my local server so that the Java file wouldn&#39;t reside in the directory that users have direct access to.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.humaneguitarist.org/2009/11/08/running-xquery-online/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

