October 17, 2011

How to Import Contacts from iPhone to an Android Phone

Recently I’ve switched from iPhone to Android device, HTC Evo 3D, and first thing I wanted to do (like anyone switching their handset will) to import my contacts. But to my surprise I found that iPhone stored all the contacts on the phone and there’s no way to copy/import the contact to SIM!

So, I decided to start adding the contacts one by one (manually) on my new phone and while doing it I realised that my Android phone has 3 options of storing the contacts – on the phone, on the SIM and on my Google account. So, I quickly started iTunes on the computer I used to sync my iPhone with. After connecting my iPhone I checked how the contacts are synced between iPhone and iTunes.

iTunes’ “Info” tab for the iPhone has option to sync contacts. It has options to sync contacts with Outlook, Windows Contacts, Yahoo Address Book and Google account. And that was my answer and solution for the problem. I selected Google Account, logged into it and synced. As soon as the sync was done I had all my contacts on my HTC phone. Awesomeness!

August 24, 2011

WordPress: Digging into Missed Schedule Problem – Part 2

OK … since my last post on the WP’s missed schedule issue I’ve gone many directions and thought I found the root cause of the issue. Although I’ve not yet found the exact problem but I do have a solid candidate for the problem.

Like I mentioned in the Part 1 of this series WP picks the second portion for the scheduled time on its own and initially I thought that is the issue. So, according to my finding what WP does is the take the second bit from the time the request was made to save the article and uses that. So I thought if two posts are scheduled for the same hour, may be the time SCHEDULE button was clicked was same causing the conflict of timestamp overlapping while creating the cron array (which is returned by _get_cron_array function).

But that does not tell me why a post that is scheduled for a different hour and the only one to be published at that time is missed once in a while. So, that could NOT be the real reason (but a possibility). So I started looking more into the publishing functionality. After going through a lot of code I wanted to run a quick test. My test relies on the fact that the environment that the WP is running on has multiple authors (sometimes sharing the same user accounts) and probably publishing articles are the same time.

So as part of the test what I did was I’ve two sessions (as author/admin) running on two windows and set two articles to be scheduled (at the same time or different times). Then I click on SCHEDULE button on two windows at the same time. After repeating the same test several times I found that one of the posts I was scheduling is not updated in the wp_options table for the option_name “cron”. Therefore, when the wp-cron runs it only publishes the one that was added and the other one shows up as missed schedule. If the post, that did not get into the cron list, is updated later (i.e. just click on SCHEDULE button again even without modifying anything in the post) it will be added in the list.

So, now I am trying to find any other way this could happen. For the time being I am thinking of an alternate way to make sure the cron list is always up to date.

August 22, 2011

WordPress: Digging into Missed Schedule Problem – Part 1

Recently, while working extensively with WordPress, I’ve come across the problem with WordPress’ Missed Schedule issue. Every now and then post(s) scheduled in a future date does not get published and shows up as “Missed “Schedule” on admin side. Searching on net is not giving me much of a direction than people suggesting to run wp-cron manually etc. So I decided to to dig into the issue and trace the root of the problem. So here is Part 1 of my finding. I am still digging to find real issue and the way to fix it.

So far I’ve manually ran part of wp-cron to find details. “wp-cron.php” makes a query into the wp_options (wp can be different as per the prefix you’ve used during WordPress installation) table in WordPress database to find the current/future processes to run. So what comes back from the query is an array like:

[1314032200] => Array (
  [publish_future_post] => Array (
    [asdasd0880as0dasdasd08] => Array (
      [schedule] =>
      [args] => Array (
        [0] => 19999
      )
    )
  )
)

Here the key of the array is the unix timestamp when the post should be published. Everything seems fine until I looked at the list of scheduled posts and for one given day I had 4 articles scheduled. But my array from _get_cron_array function only lists 1 post. 3 out of 4 articles were scheduled at the same time (for example, 2PM) so that lead me to think probably all three posts scheduled at 2PM have the same timestamp, therefore, the key is being overlapped. But it seems WP (is smart enough to) set the time at different seconds of the hour it is scheduled for. And that also explains why the 4th article (which was scheduled at a different time) was not showing up in the list.

For example, if I schedule 2 posts at 4PM WP will schedule one at 4:00:22 and one at 4:00:40. I am not sure about the pattern WP uses for the second but one thing I know when I’m scheduling a future post it only lets me specify hour and the minute. It makes sense because if we have the same timestamp it will only take one item for the timestamp in the array.

Now, like I explained the array is still missing the articles in the cron array although they have different timestamp. So I tried looking more. I let the time span to the next scheduled post and have proven that the article(s) that I do not see in the array (although they are scheduled) got missed. To quickly see what is in the array you can have a test.php in the root of WP installation and try the following code:

require_once('./wp-load.php');
$crons = _get_cron_array();
echo "<PRE>";
print_r($crons);
echo "</PRE>";

This will print the list of scheduled posts (if any). So before I dig into the code even further I decided to check the list for the next set of scheduled posts. I found another few those did not show up in the array. So I decided to edit one of the articles that is missing in the cron array. I clicked on EDIT and just pressed the UPDATE button (without modifying anything). Now when I went back to my array (refreshing test.php) I found the article listed in the array!! Now, I’ve let the cron run for the second round and the articles those were not in the array got missed and the one I manually updated got published.

So, now my next step is to dig into the scheduling functionality of WordPress to understand how does this work and what causes some of the articles getting missed from the scheduled list. I will post my finding soon after I have more on this topic.