So every once in a while I want/need to write some code that may take some time to execute. The problem is because it takes so long to execute, I need to make sure to give the user some feedback during this process so they know the page is working. If I hit submit in a page and nothing changes in my screen after 20-30 seconds I assume something is wrong. For example, I wrote a php page that would query multiple users in one db, then for each user load their xml data from another db and parse out the information to return a report for all users in the date range. Depending on the date range, this could take a few minutes to complete. This is where the php output buffer comes into play. Continue reading “ob_start(), ob_flush(), flush(), set_time_limit() – Give user feedback during execution”
Atlanta PHP December Meeting – Singleton Design Pattern and Moodle
So I attended the Atlanta PHP meeting last week and it was fun just like the previous time. I find this particular group fun and knowledgeable making me look forward to the next meeting. The topics covered this time were the singleton design pattern and the Moodle course management system. It seems like we are going to start covering a design pattern plus another topic during each future meeting which I think is a great idea. You can never know enough about design patterns.
So there wasn’t much said that was new to me about the singleton pattern. It’s pretty standard, the objective of this pattern is to prevent creating multiple instances of a class. The code example was something like this: Continue reading “Atlanta PHP December Meeting – Singleton Design Pattern and Moodle”
PHP – Copying x Files to n Folders
So a co-worker needed to find a way of coping a few files (10 files) to a bunch of folders if the files weren’t already present. Instead of doing a manual copy paste in Windows I created this code to do the above. If anyone needs to do something similar feel free to use this code. Pretty much all is does is create an array with all the folders where this PHP file is being run (this is the root where the bunch of folders reside). Then it creates another array of files – these are the files that we need to copy to all the folders. This array is created by looking in the templates folder and adding each file to the array.
The ‘foldersOnly’ function gets the array from scandir() and cleans it up. It removes the ‘.’, ‘..’, and a couple Dreamweaver folders like ‘_notes’ and another one I can remember. The new array returns only the folders we want to work with. The ‘filesOnly’ gets the array from the PHP function scandir() and returns only the files in that folder. Once we have our arrays we are ready to start.
We are going to loop for each folder and inside each folder look for each file. We check to see if the file is in the folder, if so we do nothing. If the file is not there, we copy it from the templates folder. This is pretty much it, once all the loops are done every folder should have the missing files. The code is below: Continue reading “PHP – Copying x Files to n Folders”
Uploader Phase 2 complete!
So today after work I decided it was about time to start working on phase two of my Uploader tool. Phase two consists of allowing me to drag and drop an image URL into the app so the app can then download the image to a folder in my server, create a thumbnail of this image, and update the WordPress database with information about the new image. The new image would then show up the next time a person visits my blog. If you notice, there is now a “Pics of Interest” section on the sidebar to the right of the page (similar to what people are doing with the flickr plugin). Every time I drag an image URL into the Uploader, the new image thumbnail will show in that area and if you click on the thumbnail you’ll see the full size image.
It was actually much easier than I originally thought to make this work. Technically, the Uploader already has the drag/drop functionality and already takes in a URL. The only extra AS3 code was a check to see if the URL was an image and if so call the PHP page with a code (I’m passing –@IMAGE@– to know it’s an image – it was just the first thing that came to my head) so then PHP knows this URL should be treated as an image not just a URL. If you remember, phase 1 for the Uploader allows a person to drag/drop a URL into the app so it creates a new link under the “Links of Interest”. Continue reading “Uploader Phase 2 complete!”
Atlanta PHP User Group – 11/06/2008
So I attended my first Atlanta PHP user group thanks to Moses nagging me about going :p. I’m glad I went, I had a great time. I really enjoyed being there listening and even sharing a little. The things I took with me that I’m going to mention are:
Atlanta Startup Weekend
During the meeting I found out about this really neat event. The objective of the Atlanta Startup Weekend is to get a bunch of people together, divide them into groups (developers, marketing people, business people, etc) and in one weekend finalize a product from a concept. Tickets are already sold out so I’ll have to try for next year. I’m sure I could learn a lot.
I didn’t know about this page: http://wiki.php.net/. You can get lots of neat information from the PHP group. The rfc (request for comments) section is also very informative. You can see what requests have been made, which request are going to be implemented and which have already been implemented. It’s a good way to stay ahead of the curve since you would know what’s coming out before it’s out.
Don’t quote me on any of this, this is just bits and pieces that I think I gathered from listening to others talk. If I understand correctly, REST is a standard for creating RESTful url/url/web services that are efficient and scalable… maybe? I heard REST mentioned a lot during the <head> conference a couple weekends ago and I heard it mentioned a few times last night during this meeting. So, now I need to go do some more research and figure out what this REST thing is all about. Seems like it’s something worth knowing about and maybe even following? If you have any info or resources you can recommend please do.
Uploader Phase 1
If you missed the previous post explaining what Uploader is go check it out.
So after having some fun with code I think I’m close to being done with phase 1. I currently have a working beta (0.1.0) that I’m going to share with you all and explain what I’ve done in case anyone else wants to do something similar. For the most part this was pretty straight forward. There were a few hiccups here and there that I’ll try to address in this post. The link to the code will be at the end.
Uploader: Automating WordPress Links and File Uploads
So now that I’m starting to get my WordPress and new hosting server settled in I’m trying to think of what I can create to help me automate some tasks. One of the things I know I’ll be doing quite often is adding new links to the ‘Links of Interest’ on the front page. I’ll also be uploading files/images to use on posts or to share with others but I’m too lazy to be ftping files constantly. So… time for a new tool!
The Uploader (yeah I know, I’m very creative) is going to do all the above for me. This will be a app I can keep running on my desktop somewhere and when I need to upload a file or link I can just drag it over and drop it in. The tool will then figure out what kind of item was dropped in and what to do with it.
Phase 1 will handle the links. The way the tool should work for links is the following. I visit a page that I find interesting and want to add to the ‘Links of Interest’. Instead of logging into WordPress to create it, I highlight the link from the address bar of the browser, drag it over to the app, and drop it. Now the app needs to figure out the <title> of that page to use as the name since we need a name and url to create a link. Once it has that, the tool will send the information to a PHP page which will do an insert to the links table in the WordPress DB.
Phase 2 will deal with images and files. I may break phase 2 into two since I may do some stuff differently with images versus other files. I’m thinking I may want to upload images, create a thumbnail, and insert to a DB to display in the front page the same way some people do with their flickr images. Other files I would just upload and store somewhere else. I’ll give this more thought when I get to it.
I’m going to be writing the tool in Flash CS3/AIR with PHP in the backend using the current WordPress MySQL DB. Stay tuned for updates!