Browsing all articles tagged with code

Improved parallelization of CPU-intensive tasks, Part II

OK, we’re back!

As I mentioned in the previous post (published on February 9th), here at Spin Rewriter we always strive to further improve our server infrastructure and fine-tune our code. We’re looking to deliver faster and better software that’s more intuitive and more robust than ever before.

We’ve now taken advantage of some new opportunities to parallelize certain aspects of Spin Rewriter’s existing spinning process. This means that we’re now able to run certain parts of the spinning process on multiple processors (CPUs) on different servers at the same time instead of running it on just one server.

Here’s a simplified explanation of the benefits this brings. Imagine you have an article with 20 sentences. We can either have our software detect the parts-of-speech on each of those sentences in a row, and if it takes our software one second to analyze every sentence, we’re looking at 20 x 1 second = 20 seconds of waiting time for the user.

We can, however, break this article down into 20 separate sentences — and send each of these sentences to a different server in our grid at the same time. Each of those 20 servers then processes just one sentence, and only 1 second later we get the processed results back to the central system.

The result: The same article is now fully processed in just 1 second instead of 20.

And the result that matters much more than that: Our users are even happier! 😀

Of course the exact real-world situation isn’t as cut and dry, but we were still able to roll out a significant improvement in speed and robustness of our spinning systems — and we hope you’ll love it!


Improved parallelization of CPU-intensive tasks

OK, the title of this post might sound a bit “high and mighty”, but hopefully it shouldn’t be too difficult to understand once we break it down a bit.

As you probably already know, our server infrastructure is quite state-of-the-art which allows Spin Rewriter to have great uptime and to always process all of your articles, find the best synonyms, manipulate sentence structures, export thousands of text files etc. etc. in a matter of seconds.

We always strive to further improve our infrastructure and our back-end software code. Faster, better, more intuitive, more robust — this is what drives us.

We’ve recently dug extra deeply into our software and found some new opportunities to parallelize some aspects of the spinning process. In other words, we’re now able to run a certain aspect of the spinning process on multiple processors (CPUs) on different servers at the same time instead of running it on just one server.

We’ll bring you more details in our next post, however right now we can already give you a hint that GREAT things are underway. Stay tuned! 😉



Spin Rewriter 5.0 API library now available

Good news for all developers out there: We just updated the Spin Rewriter API code samples, SDK libraries, and documentation!

Even better news for all developers: The brand-new Spin Rewriter 5.0 API is 100% compatible with older versions of our API, which means all your existing code will keep on working flawlessly without any changes required on your part. 😀

What’s new in the 5.0 version of our API?

For starters, we’ve added the new Spin Rewriter 5.0 functionality such as the ability to intelligently randomize the order of paragraphs and unordered lists when generating new articles in order to maximize their uniqueness. All of this is described in the updated API documentation.

We’ve also released brand new code samples that will get you up & running within minutes…

…and maybe most importantly, we’ve released a new version of the Spin Rewriter API SDK for PHP:

You can simply include this PHP library and starting using the Spin Rewriter API with literally 2 lines of code!

I hope you like these changes & we’ll keep on working hard to make sure it’s super easy to integrate the awesome ENL semantic spinning power of Spin Rewriter directly into your own software!


Spin Rewriter is even faster now

With yesterday’s update we managed to cut down the post-processing time (when our software is actually learning from the changes you applied to your article so it can get even better in time) a whopping 82-84%!

This means that the user experience is even smoother now, and once you click the “Continue to the Final Step” you don’t have to wait for more than a couple of seconds. If you have a good internet connection, it actually takes less than 1 second to take you to the final step. 😀

Stay tuned, we’re working hard!


A major update

Just this morning we rolled out one of the major updates of our new article rewriter, called Spin Rewriter.

This includes an even faster user interface, 65% shorter pre-processing time (when our software is figuring out the exact meaning of each word of your text), it also takes 25% less time to generate and sort lists of relevant synonyms now, and the One-Click Rewrite option almost never crashes any more. 😉

Pretty good for a beta product, right? 😀


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

Author Aaron    Category Programming     Tags , ,

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]

Author Aaron    Category Programming     Tags , ,

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

Author Aaron    Category Programming     Tags , ,

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;

Converting a DATETIME variable into a UNIX timestamp

Author Aaron    Category Programming     Tags , ,

Here’s how:

 * convert a datetime value (Y-m-d H:i:s) to UNIX timestamp value
 * @param datetime $datetime
 * @return timestamp
function datetime_to_timestamp($datetime) {
    list($date, $time) = explode(" ", $datetime);
    list($year, $month, $day) = explode("-", $date);
    list($hour, $minute, $second) = explode(":", $time);
    return mktime($hour, $minute, $second, $month, $day, $year);

Using subkey to sort an array in PHP

Author Aaron    Category Programming     Tags , ,

It’s a bit tricky to sort multidimensional arrays in PHP by one of array’s subkeys, but it can absolutely be done. Check it out:

 * USING POINTER TO ARRAY - sort an array of arrays with associative indeces by one of those associative values
 * @param $array pointer to our array
 * @param $subkey associative index that we want to order by
 * @param $sort_type [SORT_ASC|SORT_DESC]
 * @return void
function sortBySubkey(&$array, $subkey, $sort_type = SORT_ASC) {
   foreach ($array as $subarray) {
      $keys[] = $subarray[$subkey];
   array_multisort($keys, $sort_type, $array);
Follow me on Twitter! Follow me on Twitter!
You can always stay up-to-date with our latest and craziest projects ...


Monthly Archives:

I mostly write about:

Who is Aaron?

I'm a guy who started his own successful online business back in 2007. I was lucky enough to see my business expand 300+% every year.

At the moment my team and I reach over a million unique customers each month and always do our best to deliver the best quality services.