Sample Call

<?php
// SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
// $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
// $PASSWORD - variable that contains your Salesforce.ocm password

define("SOAP_CLIENT_BASEDIR", "../../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforceEnterpriseClient.php');
require_once ('../../misc/globalconstants.php');

try {
  $mySforceConnection = new SforceEnterpriseClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml');
  $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);

  $query = 'SELECT NumberOfEmployees from Lead where NumberOfEmployees != null order by NumberOfEmployees';
  $options = new QueryOptions(200);
  $mySforceConnection->setQueryOptions($options);
  $response = $mySforceConnection->query($query);
  !$done = false;

  echo "Size of records:  ".$response ->size;

  if ($response->size > 0) {
    while (!$done) {
      foreach ($response->records as $record) {
        echo $record->NumberOfEmployees."\r\n";
      }
      if ($response->done != true) {
        echo "***** Get Next Chunk *****\n";
        try {
          $response = $mySforceConnection->queryMore($response->queryLocator);
        } catch (Exception $e) {
          print_r($mySforceConnection->getLastRequest());
          echo $e->faultstring;
        }
      } else {
        $done = true;
      }
    }
  }

} catch (Exception $e) {
  print_r($mySforceConnection->getLastRequest());
  echo $e->faultstring;
}
?>

Sample Output

Size of records:  40250
0
0
1
1
1
1
...
3975
3976
***** Get Next Chunk *****
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001