custom search form, posts_per_page value being ignored

You can set the posts_per_page with pre_get_posts action like this:

add_action( 'pre_get_posts', 'my_set_posts_per_page' );

function my_set_posts_per_page( $query ){
  if ( is_admin() ){
    return;
  }

  //Check if this is a search
  if ( isset( $query->query['s'] ) ) {
    $query->set( 'posts_per_page', -1 );
  }
}

error code: 523