CAT | Web
I needed to test load some of our applications. I’m currently using a windows machine as my workstation. For some weird reason I’ve decided to develop such a load testing tool myself. It was both interesting and fun.
I used php curl extension multi_ functions that are only available since PHP5. The script is very simple. It accepts an integer parameter with max clients and a string parameter where a URL list file resides. You can run the script either from the command line or a browser. The script outputs average client response time, average responses per minute, total amount of responses and time elapsed during test loading. After a client responds the tool requests another URL. You can only stop the tool by killing the process.
You can try my php test loading tool yourself. If you are looking for something more serious try apache ab under Linux or Cygwin.
6
JavaScript Associative Arrays & Iterations
0 Comments | Posted by Žilvinas Šaltys in JavaScript, Web
Today I was working with a little piece of JavaScript code and writing something like this:
var tmp = new Array(); tmp['id']= '123'; tmp['name'] = 'bla bla';
And then i tried to iterate over the array like this:
for (var i in tmp) { alert(i); };
If you haven’t done a lot of JavaScript you would probably say that the above iteration should output ‘id’, ‘name’. Surprisingly you may be wrong. If you are using any code that extends the Array prototype with attributes or functions you will see them in the output. This may happen if you are using the prototype framework or The open source code of a JSON parser and JSON stringifier. All you’re doing is setting properties on an object. After reading a few blog posts and comments on this I found yet another issue that ideally I shouldn’t be using new Array() and using new Object(). That sounds kind of true because JavaScript does not support associative arrays and you could do the same on any object. Date, RegExp, Boolean or any other. Actually using Object solved the prototype framework problem, because prototype framework does not extend the Object prototype since 1.4 but the JSON stringifier does.
After googling a while I found out a little tricksy that may mostly work with this problem. You could do something like this:
for (var i in obj) {
if (!obj.propertyIsEnumerable(i)) continue;
foo(obj[i]);
}
This only works if properties are enumerable. That may not always save you especially if you are using any 3rd party software that breaks this, but it certainly helps you while solving the prototype framework or JSON stringifier puzzle.
9
Free multiple XHTML, HTML validator tool
0 Comments | Posted by Žilvinas Šaltys in (X)HTML, PHP, SEO, Tools, Web
If you’re working with SEO you want to make sure your website is XHTML valid. SE crawlers understand your website better if a website is XHTML valid. To make sure that a website is XHTML valid one would use http://validator.w3.org validator.
A problem arises when you need to check fifty or a hundred pages. For that particular reason I wrote a yet another extremely simple tool to validate lists of URL’s. It uses the same w3.org validator by opening the URL and searching for a phrase “page is valid”. You can check out my XHTML validator online or you can download the source code of HTML validator.
Basically all you need is a list of URLs and the validator will tell you which pages are valid and which ones are not. I hope you will find it useful. Let me know what you think by leaving a comment.
22
Free Online SEO Sitemap Crawler Tool
2 Comments | Posted by Žilvinas Šaltys in PHP, SEO, Tools, Web
The company that I work for has a lot to do with SEO, SEM, PPC. There are such a thing as sitemaps and URL lists that are used in SEO for Search Engines to optimize your site easier and better.
We have a lot of sites which have some SEO development going on. To generate these URL lists is not a task for a human being to do and I didn’t want to develop a custom sitemap generator for each of our projects.
I have tried to search for a tool that could generate these URL lists given only a single root URL. It was a while ago so I cannot say that such tools don’t exist. I also like my tools to be simple and easily extended so I developed a tool of my own. It’s a simple crawler that only needs to know the start URL and the base URL and it can find all your URLs in no time. The tool remembers the pages it has already visited. So for example let’s say I wanted to know all my blog URL’s. I just feed the crawler two URLs and wait for the results. The tool also ignores any outside URLs and adds the base URL to relative links.
You can download the crawler or try it out for yourself.
Please read comments below if you are interested why the second input field is needed.
This post describes a tool that I wrote long time ago. By now I have published a new refactored version of the XML beautifier which solves a few problems of the original tool.
I’m currently working with a system that is communicating with various third parties using web services. There are times when I need to view some of the XMLs or output them for some particular reason. Because of the last reason I wanted the beautifier to be written in PHP so that I could implement it easily. After spending some time googling with keywords like “php xml indent”, “php xml output”, “php xml human readable”, “php xml beautifier” I found that there are some code snippets or incomplete /not fully working classes / functions.
I’ve also tried pear.php.net and there indeed is a package named “XML Beautifier” that is no longer maintained. And I was frightened away by lot’s of dependencies: PEAR, XML Parser, XML Utilities, XML Beautifier .. Brrrr ..
Finally I visited phpclasses.org and found a class named “Beauty XML”. It’s simple, works but has a few bugs. So I modified the class to do the following things:
- To ignore adding a new level after if finds a tag like <tag />
- To remove all XML headers
- To remove white spaces from situations like “</tag2> </tag1>”
You can download the beauty XML or try it out yourself.
I think there still may be some XMLs that don’t get indented nicely and if i don’t find out that myself maybe You will. So please tell me if you do. I’ve also added a simple interface file to view XMLs in your web browser.
Maybe you already have or know a tool that does this job perfectly and I would be happy if you shared this with me.
18
PHP5 upgrade – DLL & version issues
8 Comments | Posted by Žilvinas Šaltys in Apache, PHP, Web
Recently I tried to update my PHP 5.2.0 version to 5.2.3 on my Windows XP machine. After the upgrade I found that phpinfo() would still show the previous version of PHP 5.2.0. Though running the “php -version” at the command line would work fine saying that my php version is 5.2.3. Later that day I also noticed that I’m unable to connect to MySQL.
Fatal Error: undefined function mysql_connect()
Though, running php -m at the command line would say, that mysql extension is ready and loaded. And phpinfo() would show it as not loaded. After checking apache’s logs/error.txt i found that php is unable to load quite a few of the php.ini enabled extensions.
PHP Warning: PHP Startup: Unable to load dynamic library ‘c:\\php\\ext\\php_curl.dll’ – The specified procedure could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘c:\\php\\ext\\php_mcrypt.dll’ – The specified module could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘c:\\php\\ext\\php_mhash.dll’ – The specified procedure could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘c:\\php\\ext\\php_mysql.dll’ – The specified procedure could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘c:\\php\\ext\\php_mysqli.dll’ – The specified procedure could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘c:\\php\\ext\\php_soap.dll’ – The specified procedure could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘c:\\php\\ext\\php_xmlrpc.dll’ – The specified procedure could not be found.\r\n in Unknown on line 0
I started googling on the matter to find out what went wrong with the upgrade. After reading a PHP bug report I realized that it might have something to do with my windows/system32 dlls. Then I found php5ts.dll in the windows/system32 directory.
It became clear to me, that PHP CLI version was using the the DLL’s from the php directory and PHP as an Apache module was loading them from the windows\system32 directory. I deleted all of the DLLs that are in the PHP directory from the windows/system32 directory and added PHP directory path to PATH environment variable and everything seems to work fine now.
My personal advice is not to put any of PHP DLL’s in the windows/system32 directory. You may really forget you have them there and become confused why things have started acting strangely.
