mysql_pconn_reuse.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. --TEST--
  2. mysql_pconnect() - disabling feature
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifconnectfailure.inc');
  7. ?>
  8. --INI--
  9. mysql.allow_persistent=1
  10. mysql.max_persistent=1
  11. mysql.max_links=2
  12. --FILE--
  13. <?php
  14. require_once("connect.inc");
  15. require_once("table.inc");
  16. mysql_close($link);
  17. if ($socket)
  18. $myhost = sprintf("%s:%s", $host, $socket);
  19. else if ($port)
  20. $myhost = sprintf("%s:%s", $host, $port);
  21. else
  22. $myhost = $host;
  23. if (($plink = mysql_pconnect($myhost, $user, $passwd)))
  24. printf("[001] Can connect to the server.\n");
  25. if ((mysql_select_db($db, $plink)) &&
  26. ($res = mysql_query('SELECT id FROM test', $plink)) &&
  27. ($row = mysql_fetch_assoc($res)) &&
  28. (mysql_free_result($res))) {
  29. printf("[002] Can fetch data using persistent connection! Data = '%s'\n",
  30. $row['id']);
  31. } else {
  32. printf("[002] [%d] %s\n", mysql_errno($plink), mysql_error($plink));
  33. }
  34. $thread_id = mysql_thread_id($plink);
  35. mysql_close($plink);
  36. if (!($plink = mysql_pconnect($myhost, $user, $passwd)))
  37. printf("[003] Cannot connect, [%d] %s\n", mysql_errno(), mysql_error());
  38. if (mysql_thread_id($plink) != $thread_id)
  39. printf("[004] Looks like the second call to pconnect() did not give us the same connection.\n");
  40. $thread_id = mysql_thread_id($plink);
  41. mysql_close($plink);
  42. if (!($plink = mysql_connect($myhost, $user, $passwd, true)))
  43. printf("[005] Cannot connect, [%d] %s\n", mysql_errno(), mysql_error());
  44. if (mysql_thread_id($plink) == $thread_id)
  45. printf("[006] Looks like connect() did not return a new connection.\n");
  46. if (($link = mysql_connect($myhost, $user, $passwd, true)))
  47. printf("[007] Can connect although limit has been reached, [%d] %s\n", mysql_errno(), mysql_error());
  48. print "done!";
  49. ?>
  50. --EXPECTF--
  51. Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  52. Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  53. [001] Can connect to the server.
  54. [002] Can fetch data using persistent connection! Data = '1'
  55. Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  56. Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  57. Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  58. Warning: mysql_connect(): Too many open links (2) in %s on line %d
  59. done!