質問編集履歴

1

アドバイスをもとに子プロセスでDB接続

2016/11/02 04:11

投稿

noripi
noripi

スコア34

test CHANGED
File without changes
test CHANGED
@@ -147,3 +147,155 @@
147
147
  }
148
148
 
149
149
  ```
150
+
151
+
152
+
153
+ 子プロセスでのDB接続を試してみましたがダメでした。
154
+
155
+ ```php
156
+
157
+ for ($i=0; $i < $pcount; $i++) {
158
+
159
+ $pid = pcntl_fork();
160
+
161
+ if( $pid === -1 ) {
162
+
163
+ debug('マルチプロセスのforkに失敗');
164
+
165
+ exit;
166
+
167
+ }elseif($pid === 0){
168
+
169
+ //子プロセス
170
+
171
+ if ($i===($pcount-1)) {
172
+
173
+ $endPage = ($endPage - $processPage) + $lastProcessPage;
174
+
175
+ }
176
+
177
+
178
+
179
+ $page = $startPage;
180
+
181
+
182
+
183
+ for ($page; $page <= $endPage; $page++) {
184
+
185
+
186
+
187
+ $result = $CrawlingContent->find('all', array(
188
+
189
+ 'conditions' => $conditions,
190
+
191
+ 'recursive' => -1,
192
+
193
+ 'limit' => $limit,
194
+
195
+ 'page' => $page,
196
+
197
+ ));
198
+
199
+ foreach ($result as $resultValue) {
200
+
201
+ debug($resultValue['CrawlingContent']['url']);
202
+
203
+ }
204
+
205
+
206
+
207
+ }
208
+
209
+ exit;
210
+
211
+ }
212
+
213
+ // 親プロセスの処理
214
+
215
+ $processes[] = $pid;
216
+
217
+ $startPage = $startPage + $processPage;
218
+
219
+ $endPage = $endPage + $processPage;
220
+
221
+ }
222
+
223
+
224
+
225
+ foreach($processes as $process) {
226
+
227
+ pcntl_waitpid($process, $status);
228
+
229
+ }
230
+
231
+ ```
232
+
233
+ エラーコード
234
+
235
+ ```ここに言語を入力
236
+
237
+ Warning Error: Packets out of order. Expected 1 received 3. Packet size=262144 in [/home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Model/Datasource/DboSource.php, line 468]
238
+
239
+
240
+
241
+ Warning Error: Packets out of order. Expected 4 received 97. Packet size=7496534 in [/home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Model/Datasource/DboSource.php, line 468]
242
+
243
+
244
+
245
+ Warning Error: Packets out of order. Expected 1 received 99. Packet size=6621798 in [/home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Model/Datasource/DboSource.php, line 468]
246
+
247
+
248
+
249
+ Warning Error: PDOStatement::execute(): MySQL server has gone away in [/home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Model/Datasource/DboSource.php, line 468]
250
+
251
+
252
+
253
+ Warning Error: PDOStatement::execute(): MySQL server has gone away in [/home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Model/Datasource/DboSource.php, line 468]
254
+
255
+
256
+
257
+ Warning Error: PDOStatement::execute(): MySQL server has gone away in [/home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Model/Datasource/DboSource.php, line 468]
258
+
259
+
260
+
261
+ Warning Error: PDOStatement::execute(): Error reading result set's header in [/home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Model/Datasource/DboSource.php, line 468]
262
+
263
+
264
+
265
+ Warning Error: PDOStatement::execute(): Error reading result set's header in [/home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Model/Datasource/DboSource.php, line 468]
266
+
267
+
268
+
269
+ Error: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
270
+
271
+ #0 /home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Model/Datasource/DboSource.php(468): PDOStatement->execute(Array)
272
+
273
+ #1 /home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Model/Datasource/DboSource.php(434): DboSource->_execute('SELECT `Crawlin...', Array)
274
+
275
+ #2 /home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Model/Datasource/DboSource.php(671): DboSource->execute('SELECT `Crawlin...', Array, Array)
276
+
277
+ #3 /home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Model/Datasource/DboSource.php(1120): DboSource->fetchAll('SELECT `Crawlin...', false)
278
+
279
+ #4 /home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Model/Model.php(3038): DboSource->read(Object(CrawlingContent), Array)
280
+
281
+ #5 /home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Model/Model.php(3010): Model->_readDataSource('all', Array)
282
+
283
+ #6 /home/scraper/public_html/ec_scraper/Controller/Component/ScrapingComponent.php(1434): Model->find('all', Array)
284
+
285
+ #7 /home/scraper/public_html/ec_scraper/Controller/Component/ScrapingComponent.php(36): ScrapingComponent->crawler_index_multi()
286
+
287
+ #8 /home/scraper/public_html/ec_scraper/Console/Command/ScraperShell.php(65): ScrapingComponent->test()
288
+
289
+ #9 /home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Console/Shell.php(458): ScraperShell->test()
290
+
291
+ #10 /home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Console/ShellDispatcher.php(212): Shell->runCommand('test', Array)
292
+
293
+ #11 /home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Console/ShellDispatcher.php(66): ShellDispatcher->dispatch()
294
+
295
+ #12 /home/scraper/public_html/ec_scraper/Vendor/cakephp/cakephp/lib/Cake/Console/cake.php(54): ShellDispatcher::run(Array)
296
+
297
+ #13 {main}
298
+
299
+
300
+
301
+ ```