Tag: php

PHP 7.3 benchmarks

My previous post about our recent upgrade to PHP 7.3 has been incredibly well received — thank you to everyone who reached out or sent me an email with follow-up questions!

The most common question of them all, though, was this:

“What kind of performance improvements and speed-ups did you notice in your particular real-world case?”

And honestly, I’m more than happy to share our results publicly, as we’ve been running benchmarks on every new version of our codebase for years now — and this way I can put those benchmarks to an even better use. 😀

Compared to PHP 5.6 that we had been previously running for a relatively long time, the newest PHP 7.3 performs amazingly well:

  • When processing large-scale data, we can now run 1,000,000 standardized operations in 0.453 seconds where that same work-load took 0.818 seconds before. These results have been measured repeatedly over roughly 100-million-op work-loads, with averages taken. That’s an 80.5% improvement!
  • When running a really complex operation on a somewhat sizable dataset, we now get the same result in 10.48 seconds that previously took 14.84 seconds — which is another 41.5% improvement.
  • And finally, under simulated heavy website traffic load, our website can now serve 285% as many requests per second as it could before! In other words, that’s a 1.85x speed-up.

These results are mind-blowing for something that required us to rewrite a relatively small part of our codebase! Although, there is a caveat…

As soon as we started the required rewrite of the incompatible parts of our code, we decided (in true programmer fashion!) to pull off a major multi-month code-refactoring effort that touches virtually all of our existing code.

And as a final result, we’re looking to get the average performance increase somewhere into the 300-400% range… while making our code even more robust!

It’s going to be a huge win for both our customers and our dev team, and we couldn’t be more excited about it! Stay tuned! 😀

Cutting-edge PHP 7.3

This past year we’ve been working so much on back-end stuff that is silently making Spin Rewriter even better and faster that I sometimes struggle to tell you about all the updates we’ve been rolling out.

Remember my recent two posts about the Spin Rewriter website switching to HTTP/2 and about the huge code refactoring process that is currently underway?

Well, a significant part of our front-end (customer-facing) code that makes the Spin Rewriter website work is written in PHP. Yes, the same good old PHP that powers 79.1% of the web, including Wikipedia, Facebook, all WordPress websites, etc.

And recently, a new version of PHP was officially released. This brand new PHP 7.3 version makes the language more robust than ever, while — and this is equally as important! — making it incredibly fast.

Now, most times when there’s an update to an already established programming language or an interpreter (which is the software that actually takes your PHP code and runs it), the improvements are absolutely minuscule.

But this recent upgrade to PHP 7.3 is vastly different. Who better to tell you all about it than the creator of PHP, Mr Rasmus Lerdorf, himself? Here’s a short video that takes you from the beginnings of PHP to what makes the newest PHP 7.3 so special…

The takeaway is this: The PHP team worked extremely closely with Intel engineers to make the newest version of the language perform as well as it possibly can on modern CPUs, with their low-level caches, branch predictors, etc.

The results speak for themselves — just check out these benchmarks!

In most cases PHP 7.3 is 150-200% or even 300% faster than PHP 5.6 which was the standard up until very recently, and what the Spin Rewriter website was running on until last year.

And at last, this brings me to my final point: YES, if you noticed a significant speed-up when using Spin Rewriter about two months ago, that was because we’ve now been running the newest PHP 7.3 on our live (production) servers for quite some time!

It’s this sort of behind-the-scenes work that makes a HUGE difference in the final user experience. And we’re happy to keep up with the times for our amazing customers — which is you guys! 😀

Spin Rewriter now recognizes even the weirdest encodings

You might have noticed I picked the “Programming” category for this blog post. The reason for this is quite simple – this post won’t be very interesting to 95% of you who aren’t programmers. 😉

You see, out of thousands of active users, we have received about 2-3 customer tickets each month saying that Spin Rewriter somehow garbled up the original text. We’ve been looking into this for a while now, and we found out that:

  • 99.5% of all submitted texts are processed normally
  • texts that begin with the bytecode EF BB BF are encoded in the standard UTF-8 format (works well with Spin Rewriter)
  • texts that begin with the bytecode FE FF are encoded in the UTF-16/UCS-2, little endian format (some issues)
  • texts that begin with the bytecode FF FE are encoded in the UTF-16/UCS-2, little endian format (some issues)
  • texts that begin with the bytecode FF FE 00 00 are encoded in the UTF-16/UCS-2, little endian format (sporadic issues)
  • texts that begin with the bytecode 00 00 FE FF are encoded in the UTF-16/UCS-2, little endian format (sporadic issues)

For instance, if our user entered “It іs nevеr a сonvenіent timе tо hаvе уour vеhicle quіt оn уоu.” in the UTF-16/UCS-2, little endian format, Step 2 of the spinning process appeared fine, however Step 3 showed this: “It Ñ�s nevеr a Ñ�onvenÑ�ent timе tо hаvе Ñ�our vеhicle quÑ�t оn Ñ�оu.”

We have now resolved all these issues and Spin Rewriter will process all articles that you can throw at it. 😉

Spin Rewriter API documentation

Okay, we just launched the Spin Rewriter API, and we thought – we should get developers on board as effortlessly as possible!

So we prepared a ton of stuff for all of you developers out there, and our efforts should enable you to integrate the Spin Rewriter API into your own apps in 10 minutes or so. Among other things you’ll find:

  • A thorough documentation of all API (HTTP POST) requests and API (JSON) responses. This will give you an idea about the inner workings of our API.
  • 100% functioning code samples (in PHP):
    – a script that will get the remaining number (quota) of API calls
    – a script that will spin your article and return the spun text (with spintax in place)
    – a script that will spin your article and return one of the possible unique variations
  • We prepared an actual official Spin Rewriter API SDK (Standard Development Kit) that’s also available in PHP. This kit comes with a number of examples, and allows you to spin your articles using the Spin Rewriter API with as little as 3 lines of code. 😉
  • A short “Q&A” section that should provide the answers to the most common questions.

You can find everything over at http://www.SpinRewriter.com/api 😀

We love developers just as much as Steve Ballmer (the Microsoft guy), and we want to make everything as easy as possible for you. Oh, and here’s a funny clip of him going just a little bit crazy. 😀

Spin Rewriter API up & running, we’re almost there!

Yup, that’s right!

Spin Rewriter API  version 1.0 is up and running, supposedly all functionality has been finished and polished, and it’s being stress-tested at the moment.

While we’re performing these final tests, we’re also writing the documentation for all of you developers out there – this way it will be extremely easy to integrate Spin Rewriter with your apps! We decided to go the extra mile and even provide fully functional code samples, as well as a Spin Rewriter SDK for the most experienced developers (at the beginning all this code will be available in PHP, however the basic principles are the same across all programming languages).

We are realistically expecting experienced developers to be able to fully integrate their app with the Spin Rewriter API in less than 15 minutes. And that’s quite a promise, we’re sure you agree! 😀

Spin Rewriter API coming out later this week!

Yes, that’s right!

We’re releasing the official Spin Rewriter API later this week. I lost count after we received something like 400 requests for an API to be added, and we’ve been working on it for almost 2 months now, so it should be pretty good. 😀

What does this mean? It means that sooner or later you will find Spin Rewriter integrated in all your favorite internet marketing applications such as SEnuke, WP Robot, etc. All you will have to do is enter your Spin Rewriter username and password within another application and this application will be able to use your Spin Rewriter account to automatically produce unique high quality content on your behalf.

We can’t wait to see what all those creative devs do with our API … so stay tuned! 😀

Spin Rewriter is FAST (once again), hooray!

You might have noticed that Spin Rewriter was a bit slow at times during these last couple of days … there’s a number of reasons for that, but – in the end – we reached our goal and made it faster than ever! 😀

The response of the Internet Marketing community has exceeded our wildest expectations, and Spin Rewriter is growing at a rate of hundreds of new users per week, which means we’re constantly upgrading our server-grid specs, tweaking settings and optimizing algorithms to make sure it works well for everyone. We finished a big part of this project about 40 hours ago, and the results that we’re seeing are amazing:

  • average server load dropped over 70%
  • 85% of all requests are now handled immediately, i.e. within 0.5 seconds (!)
  • 15% of all requests are waiting on average less than 1.5 seconds before being fully processed by our server
  • this makes the Spin Rewriter web app one of the fastest web applications available today!

We hope you love the new “snappy” Spin Rewriter, and we’ll keep on working hard to make sure you’re satisfied with us in the future as well! 😀

Creating an array of all dates between 2 specified dates [PHP]

I’ll just cut to the chase.

/**
 * create an array of all dates between two specified dates
 * @param datetime $strDateFrom
 * @param datetime $strDateTo
 * @return array
 */
function createDateRangeArray($strDateFrom, $strDateTo) {		
	$aryRange = array();
	$iDateFrom = mktime(1, 0, 0, substr($strDateFrom, 5, 2), substr($strDateFrom, 8, 2), substr($strDateFrom, 0, 4));
	$iDateTo = mktime(1, 0, 0, substr($strDateTo, 5, 2), substr($strDateTo, 8, 2), substr($strDateTo, 0, 4));
	if ($iDateTo >= $iDateFrom) {
		array_push($aryRange, date("Y-m-d", $iDateFrom));			
		while ($iDateFrom < $iDateTo) {
			$iDateFrom = $iDateFrom + 86400;
			array_push($aryRange, date("Y-m-d", $iDateFrom));
		}
	}
	return $aryRange;
}

Is this a valid URL? [PHP]

If your users link to some URL, it’s always nice to check if their input actually represents a valid URL. You can do just that with this function:


/**
 * return true if the passed variable is a valid URL address
 * @param $url
 * @return boolean
 */
function isValidURL($url) {
	$pattern  = '/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/';
	return preg_match($pattern, $url);
}

If this function returns true, you might want to actually open the URL (using file_get_contents() or some other function) to see if it works.

Convert large numbers into a more readable format

It can be tricky to really understand the value of 7312946 or 983217 at the first glance. Saying 7.3M and 983k seems like a much better option. How to convert numbers into a nicer format? Like this:

/**
 * create a nicely formatted number
 * @param $number a large number
 * @param $shorten default true = append k or M, false = format with commas and dots
 * @return int
 */
function createHumanReadableInteger($number, $shorten = true) {
	if (is_numeric($number)) {
		if ($shorten) {
			if ($number < 100000) {
				$return_int = number_format($number, 0);
			} else {
				$number_proc = $number;
				$units = explode(" ", "B k M G T P");
				for ($i = 0; $number_proc > 1000; $i++) {
					$number_proc = $number_proc / 1000;
				}
				if ($number > 1000000) {
					$return_int = round($number_proc, 2) . " " . $units[$i];
				} else {
					$return_int = round($number_proc, 1) . " " . $units[$i];	
				}
			}
		} else {
			$return_int = number_format($number, 0);
		}
		return $return_int;	
	} else {
		return 0;
	}
}