php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70080 examples SQLWorker doesn't work
Submitted: 2015-07-15 07:34 UTC Modified: 2021-02-03 12:36 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: 28181306 at qq dot com Assigned: cmb (profile)
Status: Wont fix Package: pthreads (PECL)
PHP Version: 5.6.11 OS: CentOS6.3 64bit(2.6.32-279.el6.)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: 28181306 at qq dot com
New email:
PHP Version: OS:

 

 [2015-07-15 07:34 UTC] 28181306 at qq dot com
Description:
------------
[root@localhost examples]# /usr/local/php-zts/bin/php SQLWorker.php localhost root "" test "select now()"
PHP Warning:  mysql_connect(): No such file or directory in /root/pthreads/pthreads-2.0.10/examples/SQLWorker.php on line 42
Segmentation fault (core dumped)

But, SharingResources.php works well.

More:
[root@localhost examples]# /usr/local/php-zts/bin/php -v           
PHP 5.6.11 (cli) (built: Jul 15 2015 04:45:02) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

phpinfo()
PHP Version => 5.6.11

System => Linux localhost.localdomain 2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012 x86_64
Build Date => Jul 15 2015 04:38:47
Configure Command =>  './configure'  '--prefix=/usr/local/php-zts' '--with-config-file-path=/usr/local/php-zts/etc' '--enable-fpm' '--with-fpm-user=apache' '--with-fpm-group=apa
che' '--enable-mbstring' '--enable-xml' '--with-mysql' '--with-mysqli' '--with-iconv-dir' '--enable-maintainer-zts' '--enable-zip' '--enable-pcntl' '--enable-sockets'
Server API => Command Line Interface
Virtual Directory Support => enabled


Test script:
---------------
<?php
class SQLQuery extends Stackable {
	
	public function __construct($sql) { 
		$this->sql = $sql; 
	}
	public function run() {
		/** included in 0.0.37 is access to the real worker object for stackables **/
		if ($this->worker->isReady()) {
			$result = mysql_query($this->sql, $this->worker->getConnection());  
			if ($result) {
				while(($row = mysql_fetch_assoc($result))){
					/** $this->rows[]=$row; segfaults */
					/** you could array_merge, but the fastest thing to do is what I'm doing here */
					/** even when the segfault is fixed this will still be the best thing to do as writing to the object scope will always cause locking */
					/** but the method scope isn't shared, just like the global scope **/
					$rows[]=$row;
				}
				mysql_free_result($result);
			} else printf("%s got no result\n", __CLASS__);
		} else printf("%s not ready\n", $this->worker->getConnection());
		$this->rows = $rows;
		$this->notify();
	}
	
	protected function getResults() { return $this->rows; }
}

class SQLWorker extends Worker {
	public $mysql;	
	
	public function __construct($host, $user, $pass, $db) {
		$this->host = $host;
		$this->user = $user;
		$this->pass = $pass;
		$this->db = $db;
		$this->ready = false;
		$this->name = null;
	}
	public function run() {
		$this->setName(sprintf("%s (%lu)", __CLASS__, $this->getThreadId()));
		if (($this->mysql = mysql_connect($this->host, $this->user, $this->pass))) {
			$this->ready = (boolean) mysql_select_db($this->db, $this->mysql);
		}
	}
	public function getConnection(){ return $this->mysql; }
	protected function isReady($flag = null) { 
		if (is_null($flag)) {
			return $this->ready;
		} else $this->ready = $flag;
	}
	public function setName($name) 	{ $this->name = $name;}
	public function getName() 		{ return $this->name; }
}

if (count($argv) == 6) {
	$sql = new SQLWorker($argv[1], $argv[2], $argv[3], $argv[4]);
	$sql->start();
	$query = new SQLQuery($argv[5]);
	$sql->stack($query);
	$query->wait();
	print_r($query->getResults());
} else printf("usage: {$argv[0]} hostname username password database query\n");
?>


Expected result:
----------------
1111

Actual result:
--------------
0000

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-03 12:36 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-02-03 12:36 UTC] cmb@php.net
The maintainer of PECL/pthreads has ceased its developement for
good reasons[1].  Consider to use PECL/parallel[2] instead.

[1] <https://github.com/krakjoe/pthreads/issues/929>
[2] <https://pecl.php.net/package/parallel>
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 09:01:38 2025 UTC