PHP  
 PHP_5_6
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

Test Failure Report for ext/mysqli/tests/mysqli_fork.phpt ('Forking a child and using the same connection.')

Script

1: <?php
2:     
require_once("table.inc");
3:
4:     
$res mysqli_query($link"SELECT 'dumped by the parent' AS message");
5:     
$pid pcntl_fork();
6:     switch (
$pid) {
7:         case -
1:
8:             
printf("[001] Cannot fork child");
9:             break;
10:
11:         case 
0:
12:             
/* child */
13:             
exit(0);
14:             break;
15:
16:         default:
17:             
/* parent */
18:             
$status null;
19:             
$wait_id pcntl_waitpid($pid$status);
20:             if (
pcntl_wifexited($status) && (!= ($tmp pcntl_wexitstatus($status)))) {
21:                 
printf("Exit code: %s\n", (pcntl_wifexited($status)) ? pcntl_wexitstatus($status) : 'n/a');
22:                 
printf("Signal: %s\n", (pcntl_wifsignaled($status)) ? pcntl_wtermsig($status) : 'n/a');
23:                 
printf("Stopped: %d\n", (pcntl_wifstopped($status)) ? pcntl_wstopsig($status) : 'n/a');
24:             }
25:             
var_dump(mysqli_fetch_assoc($res));
26:             
mysqli_free_result($res);
27:             break;
28:     }
29:
30:     if (@
mysqli_query($link"SELECT id FROM test WHERE id = 1"))
31:         
printf("[003] Expecting error and closed connection, child exit should have closed connection\n");
32:     else if (((
$errno mysqli_errno($link)) == 0) || ('' == ($error mysqli_error($link))))
33:         
printf("[004] Expecting error string and error code from MySQL, got errno = %s/%s, error = %s/%s\n",
34:             
gettype($errno), $errnogettype($error), $error);
35:
36:     
mysqli_close($link);
37:     if (!
$link my_mysqli_connect($host$user$passwd$db$port$socket))
38:         
printf("[005] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
39:             
$host$user$db$port$socket);
40:
41:     
/* non trivial tests require a message list for parent-child communication */
42:     
if (!mysqli_query($link"DROP TABLE IF EXISTS messages"))
43:         
printf("[006] [%d] %s\n"mysqli_error($link), mysqli_errno($link));
44:
45:     if (!
mysqli_query($link"CREATE TABLE messages(
46:         msg_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
47:         msg_time TIMESTAMP,
48:         pid INT NOT NULL,
49:         sender ENUM('child', 'parent') NOT NULL,
50:         msg TEXT) ENGINE = InnoDB"
))
51:         
printf("[007] [%d] %s\n"mysqli_error($link), mysqli_errno($link));
52:
53:     
mysqli_autocommit($linkfalse);
54:     if (!
$res mysqli_query($link"SELECT id, label FROM test ORDER BY id ASC LIMIT 3"MYSQLI_USE_RESULT))
55:         
printf("[008] [%d] %s\n"mysqli_error($link), mysqli_errno($link));
56:
57:     
$pid pcntl_fork();
58:
59:     switch (
$pid) {
60:         case -
1:
61:             
printf("[009] Cannot fork child");
62:             break;
63:
64:         case 
0:
65:             
/* child */
66:             
if (!($plink my_mysqli_connect($host$user$passwd$db$port$socket)) || !mysqli_autocommit($plinktrue))
67:                 exit(
mysqli_errno($plink));
68:
69:             
$sql sprintf("INSERT INTO messages(pid, sender, msg) VALUES (%d, 'child', '%%s')"posix_getpid());
70:             if (!
mysqli_query($plinksprintf($sql'start')))
71:                 exit(
mysqli_errno($plink));
72:
73:             
$parent_sql sprintf("SELECT msg_id, msg_time, msg FROM messages WHERE pid = %d  AND sender = 'parent' ORDER BY msg_id DESC LIMIT 1"posix_getppid());
74:             
$msg_id 0;
75:             while (
$row mysqli_fetch_assoc($res)) {
76:                 
/* send row to parent */
77:                 
ob_start();
78:                 
var_dump($row);
79:                 
$tmp ob_get_contents();
80:                 
ob_end_clean();
81:                 if (!
mysqli_query($plinksprintf($sql$tmp)))
82:                     exit(
mysqli_errno($plink));
83:
84:                 
/* let the parent reply... */
85:                 
$start time();
86:                 do {
87:                     
usleep(100);
88:                     if (!
$pres mysqli_query($plink$parent_sql))
89:                         continue;
90:                     
$tmp mysqli_fetch_assoc($pres);
91:                     
mysqli_free_result($pres);
92:                     if (
$tmp['msg_id'] == $msg_id)
93:                         
/* no new message */
94:                         
continue;
95:                     if (
$tmp['msg'] == 'stop')
96:                         break 
2;
97:                     
$msg_id $tmp['msg_id'];
98:                     break;
99:                 } while ((
time() - $start) < 5);
100:
101:             }
102:
103:             if (!
mysqli_query($plinksprintf($sql'stop')) || !mysqli_commit($link))
104:                 exit(
mysqli_errno($plink));
105:             exit(
0);
106:             break;
107:
108:         default:
109:             
/* parent */
110:             
if (!$plink my_mysqli_connect($host$user$passwd$db$port$socket))
111:                     
printf("[010] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
112:                     
$host$user$db$port$socket);
113:
114:             
$status null;
115:             
$start time();
116:             
$sql sprintf("SELECT msg_id, msg_time, msg FROM messages WHERE pid = %d AND sender = 'child' ORDER BY msg_id DESC LIMIT 1"$pid);
117:             
$parent_sql sprintf("INSERT INTO messages (pid, sender, msg) VALUES (%d, 'parent', '%%s')"posix_getpid());
118:             
$last_msg_id 0;
119:             
$num_rows 0;
120:             do {
121:                 
$wait_id pcntl_waitpid($pid$statusWNOHANG);
122:                 if (
$pres mysqli_query($plink$sql)) {
123:                     
$row mysqli_fetch_assoc($pres);
124:                     if (
$row['msg_id'] != $last_msg_id) {
125:                         
$last_msg_id $row['msg_id'];
126:                         switch (
$row['msg']) {
127:                             case 
'start':
128:                                 break;
129:                             case 
'stop':
130:                                 break 
2;
131:                             default:
132:                                 
/* client has started fetching rows */
133:                                 
$client_row $row['msg'];
134:
135:                                 
$num_rows++;
136:                                 if (
$num_rows 3) {
137:                                     
printf("[011] Child has fetched more than three rows!\n");
138:                                     
var_dump($client_row);
139:                                     if (!
mysqli_query($plinksprintf($parent_sql'stop'))) {
140:                                         
printf("[012] Parent cannot inform child\n"mysqli_errno($plink), mysqli_error($plink));
141:                                     }
142:                                     break 
2;
143:                                 }
144:
145:                                 if (!
$parent_row mysqli_fetch_assoc($res)) {
146:                                     
printf("[013] Parent cannot fetch row %d\n"$num_rowsmysqli_errno($link), mysqli_error($link));
147:                                     if (!
mysqli_query($plinksprintf($parent_sql'stop'))) {
148:                                         
printf("[014] Parent cannot inform child\n"mysqli_errno($plink), mysqli_error($plink));
149:                                     }
150:                                     break 
2;
151:                                 }
152:
153:                                 
ob_start();
154:                                 
var_dump($parent_row);
155:                                 
$parent_row ob_get_contents();
156:                                 
ob_end_clean();
157:
158:                                 if (
$parent_row != $client_row) {
159:                                     
printf("[015] Child indicates different results than parent.\n");
160:                                     
var_dump($child_row);
161:                                     
var_dump($parent_row);
162:                                     if (!
mysqli_query($plinksprintf($parent_sql'stop'))) {
163:                                         
printf("[016] Parent cannot inform child\n"mysqli_errno($plink), mysqli_error($plink));
164:                                     }
165:                                     break 
2;
166:                                 }
167:
168:                                 if (!
mysqli_query($plinksprintf($parent_sql'continue'))) {
169:                                     
printf("[017] Parent cannot inform child to continue.\n"mysqli_errno($plink), mysqli_error($plink));
170:                                 }
171:                                 break;
172:                         }
173:                     }
174:                     
mysqli_free_result($pres);
175:                 }
176:                 
usleep(100);
177:             } while (((
time() - $start) < 5) && ($num_rows 3));
178:             
mysqli_close($plink);
179:             
$wait_id pcntl_waitpid($pid$status);
180:             if (
pcntl_wifexited($status) && (!= ($tmp pcntl_wexitstatus($status)))) {
181:                 
printf("Exit code: %s\n", (pcntl_wifexited($status)) ? pcntl_wexitstatus($status) : 'n/a');
182:                 
printf("Signal: %s\n", (pcntl_wifsignaled($status)) ? pcntl_wtermsig($status) : 'n/a');
183:                 
printf("Stopped: %d\n", (pcntl_wifstopped($status)) ? pcntl_wstopsig($status) : 'n/a');
184:             }
185:             break;
186:     }
187:     
mysqli_free_result($res);
188:     
mysqli_close($link);
189:
190:     if (!
$link my_mysqli_connect($host$user$passwd$db$port$socket))
191:         
printf("[018] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
192:             
$host$user$db$port$socket);
193:
194:     if (!
$res mysqli_query($link"SELECT sender, msg FROM messages ORDER BY msg_id ASC"))
195:         
printf("[019] [%d] %s\n"mysqli_errno($link), mysqli_error($link));
196:
197:     while (
$row mysqli_fetch_assoc($res))
198:         
printf("%10s %s\n"$row['sender'], substr($row['msg'], 05));
199:     
mysqli_free_result($res);
200:
201:     print 
"done!";
202:
?>
203:

Expected

array(1) {
  ["message"]=>
  string(20) "dumped by the parent"
}
     child start
     child array
    parent conti
     child array
    parent conti
     child array
    parent conti
     child stop
done!

Output

array(1) {
  ["message"]=>
  string(20) "dumped by the parent"
}
Out of memory
Out of memory

Diff

005+ Out of memory
006+ Out of memory
005-      child start
006-      child array
007-     parent conti
008-      child array
009-     parent conti
010-      child array
011-     parent conti
012-      child stop
013- done!

 

Generated at Mon, 27 Nov 2017 05:04:32 +0000 (18 days ago)

Copyright © 2005-2017 The PHP Group
All rights reserved.