Solving slow curl and wget calls in CentOS

I recently ran into an issue with very slow curl and wget calls. After diagnosing for a while I realized that it had something to do with resolving DNS. My nameserver entries were set as and so I didn’t think the name servers were the problem.

After a lot of trial an error these are the steps I took to fix this-

In /etc/resolv.conf –
options single-request-reopen
The single line – options single-request-reopen seems to do most of the heavy lifting. Now after you do that run
sudo service network restart
Check the /etc/resolv.conf file and make sure that the changes are still there. If they are not, then you will need to do this:
In /etc/sysconfig/network-scripts/ifcfg-eth0
sudo service network restart
Then make the above changes again.
From what I can tell, there is some sort of conflict between ipv4 and ipv6. Even though the above changes will fix the problem, you might also want to disable ipv6 until the bugs are sorted out.
In /etc/sysctl.conf –
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
Then run
sudo sysctl -p
So basically if you’re running into any problems with your server connecting to other servers hopefully this will help. I specifically ran into this issue with WordPress and the Jetpack plugin as well as WordPress’s dashboard.
I’m using CentOS 7 however I believe this issue is in many other Linux distro’s.

Yii 2 – Fix weird page navigation with # (hash) symbol as you go to a new page

I ran into an issue with Yii 2 where I would click a link, it would go to that link but at the same time on the URL a little # symbol would appear then dissapear. It looks like this causes no issues until you try to navigate back. When you hit back, the page wouldn’t load but the URL would go back. Refreshing would fix it but that still isn’t good.

I figured out that this happened when using Pjax. Make sure that any links in a Pjax block have the data-pjax=”0″ parameter. So the URL would need to be like:

<a href=”/site/home” data-pjax=”0″>Home</a>

This is actually documented in the Yii 2.0 manual so if you are looking for more information you can check there.

Get & Send iPhone Location to Server via JSON with iOS 7

I recently made an app that gets a user’s location and sends it to our server. The app will update every 1000 meters when it is active and will update only during major changes when it is inactive. The location will not always been 100% correct or up to date (depending on a lot of circumstances) but if you’re wanting to get an approximate location of your users, this should work pretty well.

This code lives in my AppDelegate since I want it to run no matter what they’re doing in my app.

- (void)applicationDidBecomeActive:(UIApplication *)application
// Start location services
locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;

// Only report to location manager if the user has traveled 1000 meters
locationManager.distanceFilter = 1000.0f;
locationManager.delegate = self;
locationManager.activityType = CLActivityTypeAutomotiveNavigation;

[locationManager stopMonitoringSignificantLocationChanges];
[locationManager startUpdatingLocation];

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

// Check if running in background or not
BOOL isInBackground = NO;
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
isInBackground = YES;
NSLog(@"Location Manager isInBackground: %hhd", isInBackground);

if (isInBackground) {

// If we're running in the background, run sendBackgroundLocationToServer
         [self sendBackgroundLocationToServer:[locations lastObject]];
     } else {
         // If we're not in the background wait till the GPS is accurate to send it to the server
if ([[locations lastObject] horizontalAccuracy] < 100.0f) {
             [self sendDataToServer:[locations lastObject]];


-(void) sendBackgroundLocationToServer:(CLLocation *)location
bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
         [[UIApplication sharedApplication] endBackgroundTask:bgTask];

     // Send the data
     [self sendDataToServer:location];

     if (bgTask != UIBackgroundTaskInvalid) {
         [[UIApplication sharedApplication] endBackgroundTask:bgTask];
         bgTask = UIBackgroundTaskInvalid;

-(void) sendDataToServer:(CLLocation *)newLocation
    NSLog(@"Sending Data to Server");
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    // I also want to send the battery level to the server. Get battery level
    [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
    float batteryLevel = [[UIDevice currentDevice] batteryLevel];

    float lat = newLocation.coordinate.latitude;
    float lng = newLocation.coordinate.longitude;
    NSLog(@"Accuracy: %f", newLocation.horizontalAccuracy);
    NSString *userId = [[NSUserDefaults standardUserDefaults] stringForKey:@"userId"];

    // This is the data I am sending to the server
    // I am sending a userID that the server recognizes
    // I am sending the latitude and longitude of the user as well as their speed course and battery life
    // I am also sending the horizontal & vertical accuracy so I can see how accurate the gps location was
    NSString *post = [[NSString alloc] initWithFormat:@"login_id=%@&latitude=%f&longitude=%f&speed=%f&course=%f&battery_level=%f&horizontal_accuracy=%f&vertical_accuracy=%f",
       [newLocation speed],
       [newLocation course],

     NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

     NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

     NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
     NSString *urlstring = [NSString stringWithFormat:@"[email protected]/post_logins_location.php", kBaseURL];
     [request setURL:[NSURL URLWithString:urlstring]];
     [request setHTTPMethod:@"POST"];
     [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
     [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
     [request setHTTPBody:postData];

     NSError *error;
     NSURLResponse *response;
     NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

     if (!error) {
         jsonResults = [NSJSONSerialization JSONObjectWithData:urlData options:kNilOptions error:&error];
         NSLog(@"GPS Send results: %@", jsonResults);
    } else {
         NSLog(@"Error sending GPS data to server");

- (void)applicationDidEnterBackground:(UIApplication *)application
    NSLog(@"Went to Background");
// Only monitor significant changes
    [locationManager startMonitoringSignificantLocationChanges];

I chose to use startMonitoringSignificantLocationChanges when in the background. From what I’ve read this only updates when the phone changes radio towers and is not very accurate. For my purposes, this was fine. I’m just trying to get an idea on where the phone is.

And that should do it. Please let me know if I have any syntax errors (I’m sure I do).

Error 691 when connecting through VPN on Windows 8 or Windows 10

After upgrading to Windows 8, I ran into an issue where I couldn’t VPN into my old Windows Server 2003 machine anymore. I kept getting this error:

Error: 691: The remote connection was denied because the user name and password combination you provided is not recognized, or the selected authentication protocol you selected is not permitted on the remote access server.

I know that my username and password is correct so I figured it must be something else. Turns out, it’s an easy fix.

  1. Open your VPN connections properties.
  2. Go to the security tab
  3. Check “Allow these protocols” and make sure “Microsoft CHAP Version 2” is checked

    Fixing VPN Error 691 in Windows 8

    Select the radio button for “Allow these protocols”

  4. That’s it

I’m guess this is a bug of some sort. Once you select one of the two radio buttons, you can’t deselect them which leads me to believe that it is a bug. Hopefully this will be fixed in an upcoming Windows update.

Java not working in Chrome on OS X (Lion)

If you have upgraded your browser to Lion, you have probably noticed that Java doesn’t run in your browser anymore. From what I can tell, it doesn’t run in any browser. It’s a pretty easy fix.

Open terminal and type:

/Applications/Utilities/Java\\ Preferences
 This will downloading some files and do an installation. Once it is complete, the Java Preferences will appear. In Java preferences, check the box that says “Enable applet plug-in and Web Start applications.”
Click "Enable applet plug-in and Web Start application"

Click “Enable applet plug-in and Web Start application”

Once you do this, Java should be working in your browsers.