Posted on Sep 05, 2014 By Philip Whitt



Need to generate random users for test data in your php app? Randomuser.me is a wonderful solution and here is the PHP client.

Install via composer:

{
    "require": {
        "randomuser/generator"  : "dev-master"
    }
}

Using the PHP Generator:

<?php

$gen = new \RandomUser\Generator();
$user = $gen->getUser();

You can also get many users using:

<?php

$gen = new \RandomUser\Generator();
$user = $gen->getUsers(10);
Which returns an array of 10 User objects.


The User object returned is of similar structure the the Randomuser.me api, but flat.
class User {
	$gender;
	$firstName;
	$lastName;
	$streetAddress;
	$city;
	$state;
	$zip;
	$email;
	$username;
	$password;
	$salt;
	$md5;
	$sha1;
	$sha256;
	$registered;
	$dob;
	$phone;
	$cell;
	$SSN;
	$picture;
}

Getters and setters are available for all properties. 


This package is tested using phpunit. To run the tests:
$ phpunit test

Fork it on github!

https://github.com/philipwhitt/randomuser-client

Randomuser.me documentation:

http://randomuser.me/documentation.html


Back to Blog