 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Josh Adell: Serializing Data Like a PHP Session
by Chris Cornutt May 02, 2013 @ 09:11:33
In this new post Josh Adell looks at working with PHP sessions and how you can manually encode data to look as if it came from the normal session handling.
If you have ever popped open a PHP session file, or stored session data in a database, you may have noticed that this serialization looks very similar to the serialize function's output, but it is not the same. Recently, I needed to serialize data so that it looked like PHP session data (don't ask why; I highly suggest not doing this if it can be avoided.) It turns out, PHP has a function that encodes data in this format: session_encode.
Unfortunately, this method doesn't take arguments - it just outputs the encoded version of the current session data. So, he came up with his own encode/decode methods that use the PHP session, extract the serialized string and return it.
voice your opinion now!
serialize data session string unserialize
Etsy Code as Craft: There and Back Again Migrating Geolocation Data to GeoNames
by Chris Cornutt April 01, 2013 @ 11:48:36
On the Etsy "Code as Craft" blog there's a recent post about their move to using the GeoNames service internally rather than the external, third-party API previously in use.
People are passionate about where they live. At Etsy we need to keep track of lots of different locations, such as buyers' billing and shipping addresses and sellers' shop locations. As Etsy continues to expand internationally we wanted to provide better localization and translations for our location place names. We determined that the best way to effect this change was to move from using a closed location API provider to internal services backed by the open GeoNames data set.
The post details some of the steps in the process including the mapping of the current data to the new structure (the script is available on github). They talk about how they mapped their old data over (trial and error sometimes) and the creation of a database of "GeoNameIDs" for each customer in their records. They've also implemented a Lucene/Solr search for improved searching and auto-suggestion based on the user's location.
voice your opinion now!
data migration geonames geolocation api script
Sameer Borate: Storing images into a database - resolving a contentious matter
by Chris Cornutt February 21, 2013 @ 11:16:45
In this new post to his CodeDiesel site Sameer Borate looks at something that's been a controversial topic with developers (not just PHP) about storing binary data, like images, in a database instead of on the local file system.
There is much discussion and argument with no final say on the issue. In one of my recent project the same issue was raised; the client and myself discussing the benefits and drawback of storing the images into a database. The project needed storing around 50,000 images, so it was important to get the question resolved satisfactorily. After much deliberation we settled on using the file system. The major factor in the decision was that we needed the database and images decoupled as we would be having multiple databases using the same set of images.
He goes on to talk about some of the things you should consider when you're deciding if storing images in the database is the right thing for your application including:
- The bloat that can come with storing binary data (larger database size)
- Updating images requires two operations - updating the database and updating the cached image locally
- Images usually serve faster when they come from the filesystem through the web server
- BLOB (a common type for binary data storage) is variable-width and can degrade performance
You can read the rest of the reasons (and get more detail on the ones above) in the rest of the post.
voice your opinion now!
images binary data storage database benefits disadvantages
PHPMaster.com: Simplifying Test Data Generation with Faker
by Chris Cornutt February 19, 2013 @ 12:09:02
In a new post to PHPMaster.com today, Rakhitha Nimesh takes a look at Faker, a tool that can be used to generate random test case data as a part of your workflow.
Testing is an iterative part of the development process that we carry out to ensure the quality of our code. A large portion of this entails writing test cases and testing each unit of our application using random test data. Actual data for our application comes in when we release it to production, but during the development process we need fake data similar to real data for testing purposes. The popular open source library Faker provides us with the ability to generate different data suitable for a wide range of scenarios.
Faker uses built-in data providers like "Person", "Company", "DateTime" and "UserAgent" to give you randomized output from the data sets you define. Code is included showing how to create the provider in your objects, extending the correct provider and making a request for a property. A real-world example is also included about testing an email marketing engine for address, title, name and content. There's also a little bit added at the end showing how you can increase the randomness of the results returned by "seeding" the Faker engine.
voice your opinion now!
test data generation faker library object provider tutorial
PHPWomen.org: Add values to a symfony form in between save() and serialization to the database
by Chris Cornutt October 05, 2012 @ 08:55:12
Kim Rowan has recently posted this helpful hint to the PHPWomen.org site concerning the addition of values between save/serialization in Symfony (1.4) forms.
OK, I have a Comment model and I want to relate Comment objects to several other different model types. So, I need to be able to persist Comment objects in my database that relate to the author of the comment and one of a handful of other tables, for example, a blog post or a licence record, etc.
She includes the contents of her "schema.yml" definition and the code to create and display a basic form. Inside of her "executeCreate", the form's submission is handled and a "processForm" method is called and the overridden "updateObject " is used to inject the new data (a user ID) into the submission.
voice your opinion now!
symfony form tutorial override save object inject data
PHPBuilder.com: Handling Hierarchical Data in MySQL and PHP
by Chris Cornutt September 06, 2012 @ 10:16:44
On PHPBuilder.com today there's a new tutorial showing you a way to work with hierarchical data in MySQL from your PHP application in two different ways (methods).
The hierarchical data structure is one of the most common data structures in programming. It represents a set of data where each item (except the root) has one parent node and one or more children nodes. Web programmers use hierarchical data for a number of applications, including content management systems, forum threads, mailing lists, and e-commerce product categorization. In this tutorial , I will explain how to manage hierarchical data using MySQL and PHP. Specifically, I will explore the two most popular hierarchical data models: adjacency list model and nested set model.
They start with the adjacency list model, showing how to do a left join on the table on the parent ID to record ID and then filter through them, merging them into a main array as needed. The nested set model is slightly different and involves two new columns, a "lft" and "rgt", that point you to the records around the current one. This method makes the actual SQL query to find the structure a bit simpler, but isn't quite as flexible as the first method.
voice your opinion now!
hierarchical data mysql tutorial nestedset adjacencylist
|
Community Events
Don't see your event here? Let us know!
|