08.14.08

Playing nice with CPU usage

Posted in PHP, System Administration at 4:32 pm by BrianS

I needed to do a mass resampling of around 280,000 images. There are a number of ways to do this, but I settled on doing it via PHP because the images are stored on our web server, the total size of the images is large (~10GB), and I didn’t want to kill my machine trying to get it done.

PHP is ideal for a task such as this: parsing directories and subdirectories for images is easy; resampling using the built-in library (GD) is a breeze; specifying the destination as a subdirectory is simple. The one minus was processor usage. Performing image manipulation eats up the CPU in a big way.

Luckily linux systems have a built-in utility for addressing a situation like this: nice. nice will “run a program with modified scheduling priority.” I’m running the image manipulation script using the following command:

nice --adjustment=19 php script.php

If nothing else is going on the script will use whatever resources are available. When anything with a higher priority executes, that program will take precedence over the script with regard to system resources. The script should thus not affect the responsiveness of the web server. This is the reason I was searching for this kind of functionality.

06.19.08

Creating Graphs in PHP

Posted in PHP, Web Development at 3:13 pm by BrianS

I was tasked with creating a demonstration of a dynamically generated graph for one of the grant proposals being worked on at present. This isn’t something we’ve really done before in PHP, but I had a feeling it would not be a unique requirement. A quick search revealed that a PEAR package exists for just this purpose: Image_Graph.

Installation was not too difficult, though I did have to ensure that a few dependencies were installed before PEAR would load the package. Documentation for the module is not that great, but there are a number of samples and a fairly active discussion forum.

I did not find the graphing object very intuitive. It seems to me that a lot of the properties and functions are abstracted from the objects they affect. I suspect this was a design decision to allow for greater flexibility, but it may also be due to an older coding style. The current branch appears to have been developed in earnest starting in 2005, and it’s been a few years since a new release. Even so, my initial exposure leads me to believe the package may be stable enough for even a production-level project so long as sufficient QA has been performed.

It took me only a couple of days to hack together the demonstration. Though the requirements of the script were few, I decided to push the limits of my object-oriented PHP and create the graphing component as a class. Overall it was a good first-try at producing something of this nature. You can find the demonstrator at http://flora.p2061.org/weather_data/.

06.18.08

Items Utility: Piloting Data Entry Updates

Posted in PHP, Web Development at 5:05 pm by BrianS

Piloting packets for this year are starting to come in and the data from these packets needs to be entered into the items utility. Because the questions in the packet have changed from previous years, and due to the rigid structure of the piloting data entry form and data tables, I decided to rewrite the data entry form. The new format allows more flexible on the front-end without requiring modification of the back-end. In addition I modified the way PHP interacts with the packet data from MySQL by utilizing a structured array to hold the data.

Read the rest of this entry »

05.21.08

Using Subversion for Application Development and Deployment

Posted in PHP, System Administration at 3:25 pm by BrianS

I recently wanted to update our install of WordPress to the latest version. WordPress is a fairly easy install, and we could learn a thing or two about application set-up by examining their code. But I recently switched to using subversion to deploy and maintain our install. In just the little bit I’ve used subversion so far, I believe development and deployment of our internal applications would be simplified by employing it for all our projects. Here’s a quick outline of the process, with examples based on my WordPress deployment.

Read the rest of this entry »

05.14.08

Expanding Search Terms for More Inclusive Results

Posted in MySQL, PHP, Web Development at 11:54 am by BrianS

While working on the Benchmarks search I wanted to try and provide a feature I find useful on Google and other search engines: word form expansion (lemmatisation). A little research showed to me that this would require more work than we really should be spending on search functionality. Especially considering that the built-in MySQL full text search capability is sufficient for our needs. So I decided to focus on a feature that would still provide value but require little time: word stem expansion.

Read the rest of this entry »

05.13.08

Items Utility: School Reports Update

Posted in PHP, Web Development at 4:09 pm by BrianS

I made a few updates to the school reports at the request of the researchers.

  • Added a save feature so that packet/item selections for a report can be retrieved at a later date.
  • Added the ability to set thresholds that must be met before the script will include statistics in the report.
  • Updated tables to reflect changes in displayed information and formatting.

In regards to the above changes, the save feature is of particular note for it inscrutibility. While the technique used to save/retrieve the report setting is adequate, the code to enable this functionality is not well-implemented. Unfortunately, time constraints required a fast, rather than best, implementation.

As modifications are requested this script is getting to be a little harder to work with. The code was created over the course of a week or two back in January. I was able to make quick work of it by using some concepts I initially worked out for summary table generation (and based on discussions with Brian W). While the data is stored in a psuedo object-oriented format, the script itself is fairly linear in design. If more modifications are requested the script may need some rewrites to enable a bit more flexibility.

03.18.08

Items: Summary Tables Update

Posted in PHP, Web Development at 2:22 pm by BrianS

The number produced by summary table 8 in the items utility were not quite correct. The researchers noted that the means by which calculation of answer selection was performed was not quite as they wanted it.

Luckily table 8 uses a new summary table generation technique I borrowed from the school reports. The data, display, and summarization code is segregated to a certain degree (though not as much as would be preferred). This allows me to update one aspect of the script without having to monkey around too much with other aspects.

The data is currently stored in a data array that is organized to allow for relatively easy access. The summary information is currently compiled inline in the code. While this isn’t ideal, the method used (summary arrays) should allow for better segregation in the future. The calculation of concern is stored in its own function, answer_selected(). That function includes some basic versioning capability and so I was able to add a new version of the calculation that matches the researchers expectation without changing anything else in the code.

I think a modification of this technique would work well for all tables in the utility and should not require significant investment in development time. As additional tables need work I may investigate adding them as components of the new summary table script (summary_table.php).

03.11.08

IIS and PHP

Posted in PHP, System Administration at 9:53 am by BrianS

IIS can’t find php.ini

I installed PHP on the Windows server today and ran into what seems to be a fairly common problem (BrianW can affirm): sometimes PHP is unable to find the php.ini file when processing web-based content. In my case PHP was installed as an ISAPI filter. I suspect that when using the ISAPI filter PHP must be looking in the in the location IIS is running from, rather than the location of the ISAPI DLL (which is located in the PHP folder).

To address the problem I added a PHPRC environment variable. Now everything seems to work as expected. There are a number of options for specifying the location of the php.ini file. See the PHP documentation for runtime configuration.

IIS returns an error

If you’ve fully set up PHP and configured IIS correctly (including enabling the Web Service Extension) then one last thing to check is the path to the DLL specified for the Web Services Extension vs. the value for the application extension in the web site properties. These should match exactly.

03.05.08

BOL updates

Posted in PHP, Web Development at 5:43 pm by bwalker

The search upgrades and bug fix have been implemented and uploaded to flora and floradev.

http://flora.p2061.org/benchmarks/

http://floradev.p2061.org/benchmarks/

Search filtering by current bm, old bm, prose has been corrected.

Fulltext viewing is now available for each search result (’fulltext’ link following the truncated text), or all search results (’Output Format’ menu option).

A new results formating option currently labeled ‘Custom1′ is in the Output Format’ menu which displays the results in table format similar to old BOL search result output.

Files updated:
index.php, bol_search_func.php, bol.js

02.11.08

Misconceptions misnumbering

Posted in MySQL, PHP at 1:57 pm by bwalker

Jill is working on a new topic (

Processes that shape the earth/Plate Tectonics Version II (PT)) which shares a number of misconceptions with another topic (Earth Science: Processes that shape the Earth / Plate Tectonics (EP)).

Problem: She changed the topic of those misconceptions believing it would be available to both topics. Once she realized this was not the case, she changed the topic back, but the numbering was off.

Solution: She provided me a list of which misconceptions were out of sync. Because adding a misconception involves updating multiple tables I actually had to add the misconceptions through the Item interface and then change the numbering on the backend.

Conclusion: The conclusion is that the conclusion is pretty obvious. This functionality needs to be revised. Changing the topic of a misconception has considerable consequences throughout the Items utility, so I think it may be necessary to add an additional step to this process. For example, have the current topic displayed along with a check box and a disabled/hidden topic menu. Then use the checkbox to enable/disable the menu and possibly some kind of textual warning (”Changing this is likely to break something.”).

Another note is that the ‘code’ column denoting the numbering sequence is not a unique column so we could have the numbering be editable on the interface. Although this could have some duplication complications.

I also found it strange that when submitting a new misconception, there is no notification and you are not redirected back to the miscon list. I found out the hard way that once you submit a misconception you are essentially in edit mode (not Add New Miscon anymore) and any changes made are being made to the record you just added. It wasn’t obvious to me the difference between Add and Edit mode.

« Previous entries