Here's how you'd do it using daniil.it/MadelineProto:
try {
$MadelineProto = \danog\MadelineProto\Serialization::unserialize('session.madeline'); // Unserialize a stored session, if you haven't saved it yet, login first, see below
} catch (\danog\MadelineProto\Exception $e) { // If
$MadelineProto = new \danog\MadelineProto\API();
// Login as a user
$sentCode = $MadelineProto->phone_login($number);
echo 'Enter the code you received: ';
$code = '';
for ($x = 0; $x < $sentCode['type']['length']; $x++) {
$code .= fgetc(STDIN);
}
$MadelineProto->complete_phone_login($code);
}
$inputContacts = [];
$inputContacts[0] = ['_' => 'inputPhoneContact', 'client_id' => 0, 'phone' => '+172737', 'first_name' => 'first', 'last_name' => 'last', ];
$inputContacts[1] = ['_' => 'inputPhoneContact', 'client_id' => 0, 'phone' => '+172737', 'first_name' => 'first', 'last_name' => 'last', ];
// You can add maximum 4000000000 contacts
$contacts_ImportedContacts = $MadelineProto->contacts->importContacts(['contacts' => $InputContacts, 'replace' => false, ]);
$MadelineProto->serialize('session.madeline');