I know guys, this question has been answered but belive me before I ask it I followed step by step these two questions but still having the same error.
pthread not working in php
PHP pthreads: Fatal error: Class 'Thread' not found
I have added this line extension=php_pthreads.dll to the php.ini file located in the apache directory C:\wamp\bin\apache\apache2.4.9\bin\php.ini.
Also I have the file pthreadVC2.dll under C:\wamp\bin\apache\apache2.4.9\bin, and the file php_pthreads.dll under C:\wamp\bin\php\php5.5.12\ext.
After that I restarted the wamp server and checked the php_pthreads extension and it's activated.
I did everything as described but still facing this error.
This is my class that extends from Thread:
class MyThread extends \Thread
{
public function run()
{
echo 'This is a thread';
}
}
And this is how I called it:
$myThread = new MyThread();
$myThread->start();
You should use pthreads 2.0.10 for PHP version 5.5.12. You should also try copying pthreadVC2.dll and php_pthreads.dll at your c:/windows/system32 directory.
Related
When I try to run PHPUnit in Netbeans I face this error:
Fatal error: Class 'PHPUnit_Framework_TestSuite' not found in C:\Users\julian\AppData\Roaming\NetBeans\8.2\phpunit\NetBeansSuite.php on line 63
Done.
This happens both in Netbeans and CLI.
I started debugging this problem by navigating to this directory: C:\Users\julian\AppData\Roaming\NetBeans\8.2\phpunit\.
That directory contained one file: NetBeansSuite.php. I opened it to look for clues, and saw this line:
class NetBeansSuite extends PHPUnit_Framework_TestSuite {
What I didn't see is any concrete PHPUnit_Framework_TestSuite class.
What's next is that the NetBeansSuite.php file doesn't have any include or require language constructs that may include the PHPUnit_Framework_TestSuite class.
So, in order to fix the fatal error problem I should include the PHPUnit_Framework_TestSuite in NetbeansSuite.php.
This is a problem because I'm not the author of NetbeansSuite.php.
On top of that the author of NetbeansSuite.php wrote this in the comment section:
<b>WARNING: User changes to this file should be avoided.</b>
I read further in the comments:
* Copyright 2010 Oracle and/or its affiliates. All rights reserved.
I guess the NetbeansSuite.php file is outdated.
Searching on the net brought me to this stackoverflow question:
Why, Fatal error: Class 'PHPUnit_Framework_TestCase' not found in ...?
They claim that using a namespaced version of PHPUnit_Framework_TestCase should fix the problem. So I did what they wrote.
I stubbornly changed NetBeansSuite.php.
Old code:
class NetBeansSuite extends PHPUnit_Framework_TestSuite {
New code:
require_once 'PHPUnit/Autoload.php';
use PHPUnit\Framework\TestCase;
class NetBeansSuite extends TestCase {
I tried to run the test case again, and this was the unfortunately result:
Fatal error: Declaration of CalculatorTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in C:\wamp64\www\test\CalculatorTest.php on line 97
In other words, it gave me a new problem.
My system:
Windows 10
WAMP
php 7.2.14
PHPUnit 8.0.6
Netbeans version 8.2 (Netbeans PHPUnit plugin installed through Tools > Plugins. Version: 0.26.2)
My question is: does anybody know how the NetBeansSuite.php file should be like with the system described above?
The setUp method in my test case:
protected function setUp()
{
$this->object = new Calculator;
}
Update: The Skeleton Generator project is abandoned.
See link: https://github.com/sebastianbergmann/phpunit-skeleton-generator
So in order to fix the Declaration of CalculatorTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp() error the corresponding return type declaration should be used in the test case.
// I added : void
protected function setUp(): void
{
$this->object = new Calculator;
}
// : void needs to be added in the tearDown method as well
protected function tearDown(): void
Unfortunately, this gave me new problems:
Warning: require_once(PHPUnit/Autoload.php): failed to open stream: No such file or directory in C:\wamp64\www\test\CalculatorTest.php on line 4
Fatal error: require_once(): Failed opening required 'PHPUnit/Autoload.php' (include_path='.;C:\php\pear') in C:\wamp64\www\test\CalculatorTest.php on line 4
I solved this by manually installing PEAR and creating a new "PHPUnit" directory in C:\php\PEAR. Then I created a new Autoload.php file. I filled the content of Autoload.php with a PSR-4 example file found at: https://www.php-fig.org/psr/psr-4/.
This solved the Autoload problem, but I faced a new problem during the execution of a test case.
C:\wamp64\www\test>phpunit CalculatorTest.php
PHPUnit 8.0.6 by Sebastian Bergmann and contributors.
Time: 170 ms, Memory: 10.00 MB
No tests executed!
It shows No tests executed! but I have 5 tests.
I'll make a new question for this.
Here it is: PHPUnit 8 installed on Windows through PHAR shows No tests are executed
Initially indeed you should update your namespaces since it has been changed in more recent versions of PHPUnit.
The error however indicates that your CalculatorTest::setUp() method is not compatible with the PHPUnit version. Could you maybe post that method here?
For the same issue, I directly changed the file "NetBeansSuite.php" (C:\Users\USERNAME\AppData\Roaming\NetBeans\8.2\phpunit) as following :
class NetBeansSuite extends \PHPUnit\Framework\TestSuite {
After that, CLI and Netbeans was working.
The php function yaml_emit_file() is not working. I have installed and included the php_yaml.dll in my php.ini file restarted the server but still when I use this function, I get this error (when I run composer):
Call to undefined function RS\composer\yaml_emit_file()
Okay so a little about the background:
PHP version 7.1.7 & Composer version 1.5.1
I am using this function in a ScriptHandler.php file which is invoked when Composer is run. In this script I have a function buildModuleList which is called on post-update-cmd event of Composer. Everything else in the code is working fine.
I am in doubt that maybe I am using this function in wrong context or something like that.
Here is the code snippet where I am using yaml_emit_file() (Providing this just for reference, tell me if am using it the wrong way!):
if (!$fs->exists($moduleListFile)) {
$fs->touch($root.'/profiles/thunder/modulelist.yml');
$fs->chmod($root . '/profiles/thunder/modulelist.yml', 0666);
if(!empty($moduleList)){
$createyml= yaml_emit_file($moduleListFile, $moduleList);
if (!$createyml){
$io->writeError('<error>Cannot create modulelist.yml</error>');
}
}
$io->write('Success: Created new modulelist.yml', $newline= TRUE);
}
else{
$fs->file_put_contents($moduleListFile, $installedPackage, FILE_APPEND);
$io->write('Success: Module entry in modulelist.yml', $newline= TRUE);
}
i hope this help someone i test it on
Windows 10
XAMPP v3.2.4
PHP 8.0.2
Download the latest YAML DLL Package from : https://pecl.php.net/package/yaml
Unzip the files
Move the php_yaml.dll file to xampp/php/ext folder
Open your php.ini in xampp/php add a new line extension=php_yaml.dll, save and exit
Restart your XAMPP Servers
make a PHP file put into
<?php
phpinfo();
?>
Search the string yaml on the page. If it says Enabled then your YAML Extension is working.
I want to use thread in PHP . I am using windows . What needs to be done to do this . Here is the code i am running .
<?php
class AsyncOperation extends Thread {
public function __construct($arg){
$this->arg = $arg;
}
public function run(){
if($this->arg){
printf("Hello %s\n", $this->arg);
}
}
}
$thread = new AsyncOperation("World");
if($thread->start())
$thread->join();
?>
When i run the code it shows
Fatal error: Class 'Thread' not found in D:\xampp\htdocs\my.php on line 2
Thanks in advance
It seems like the pthreads extension is not installed on your system.
It's a custom PHP extension not by default installed with XAMPP.
Go fetch it.
You find pthread releases for Windows over at http://windows.php.net/downloads/pecl/releases/pthreads/
Add pthreadVC2.dll to the same directory as php.exe, e.g. C:\xampp\php
Add php_pthreads.dll to PHP extention folder, eg. C:\xampp\php\ext
Then modify php.ini by adding extension=php_pthreads.dll in the extensions section.
The code you posted is a basic example, which should work right out of the box, when the extension is installed.
And a goodie on top:
Video by Joe Watkins explaining "Parallel PHP"
I use php5.5 on my webserver. Now I want to use pthreads. Here's my php config: http://dd19010.kasserver.com/infophp.php55
After implementing this code.....
<?php
class AsyncOperation extends Thread
{
public function __construct($threadId)
{
$this->threadId = $threadId;
}
public function run()
{
printf("T %s: Sleeping 3sec\n", $this->threadId);
sleep(3);
printf("T %s: Hello World\n", $this->threadId);
}
}
$start = microtime(true);
for ($i = 1; $i <= 5; $i++) {
$t[$i] = new AsyncOperation($i);
$t[$i]->start();
}
echo microtime(true) - $start . "\n";
echo "end\n";
?>
... the problem is this very error: Fatal error: Class 'Thread' not found in.
Do I have to include some include_once or something similar to make it work?
What do I have to do??
Hi I encountered this problem and managed to solve it.
First, consider the VC version of your PHP and the VC version of extension. In mine I attached the extension pthreads.dll with version VC14 from http://windows.php.net/downloads/pecl/releases/pthreads/ but my PHP VC version is VC11. Look for the lower version to match with the VC version of your PHP.
Second, maybe you missed the step #3 at PHP page. It states that you need to copy the pthreadVC2.dll to different folder. Here's the full instruction.
Find out what is your 'PHP Extension Build' version by using phpinfo(). You can use this - http://localhost/?phpinfo=1
Download the pthreads that matches your php version (32 bit or 64 bit) and php extension build (currently used VC11). Use this link for download - http://windows.php.net/downloads/pecl/releases/pthreads/
Extract the zip -
Move php_pthreads.dll to the 'bin\php\ext\' directory.
Move pthreadVC2.dll to the 'bin\php\' directory.
Move pthreadVC2.dll to the 'bin\apache\bin' directory.
Move pthreadVC2.dll to the 'C:\windows\system32' directory.
Open php\php.ini and add
extension=php_pthreads.dll
Reference: https://secure.php.net/manual/en/pthreads.installation.php
1) Create one php file
phpinfo(); --> Run
Example: Info
PHP Version: 5.6.31
Compiler: MSVC11 (Visual C++ 2012)
Architecture: x64
2)Go to website:
http://windows.php.net/downloads/pecl/releases/pthreads/
Example 2.0.9 file
Compiler:VC11
Architecture:x64
php_pthreads-2.0.9-5.6-ts-vc11-x64.zip download.
3)Extract php_pthreads.dll and pthreadVC2.dll.
wamp\bin\php\php5.6.31\ext\ --> copy php_pthreads.dll
wamp\bin\php\php5.6.31\ --> copy pthreadVC2.dll
wamp\bin\apache\apache2.4.27\bin --> copy pthreadVC2.dll
4)Now edit php.ini
wamp\bin\apache\apache2.4.27\bin\php.ini\ --> Add extension=php_pthreads.dll
wamp\bin\php\php5.6.31\php.ini\ --> Add extension=php_pthreads.dll
5)Now Restart Wamp
Your phpinfo shows that you have php with thread safety disabled. You need to install a version of php that is thread safe to use pthreads. This may or may not fix your current issue though.
You may need to copy the pthreadsVC2.dll into the bin directory of your web service as well.
/etc/php55/fpm/
You're looking for the folder with php.ini in it.
Make sure the php.ini file has the line added:
extension=php_pthreads.dll
I am using WAMP and found that the pthreadVC2.dll should go to the Apache folder instead:
C:\wamp\bin\apache\apache2.4.9\bin
Unlike what is written in README.md, you don't need to have it in the PHP folder, but the php_pthreads.dll should still go to:
C:\wamp\bin\php\php5.5.12\ext
After this, search in this file:
C:\wamp\bin\apache\apache2.4.9\bin\php.ini
For ;extension=php_pgsql.dll and add extension=php_pthreads.dll in a new line after it (yes, it's the bin\php.ini in the Apache folder, not the one in the PHP folder).
Exit WAMP and start it again. You should now see in WAMP menu under PHP > PHP extensions, the new php_pthreads extension.
I think you need to include the extensions int he php.ini file, because I can't see it in the config. You can see that each library has its own section like MySQL, but there isn't such for the threads. I haven't used threads ever but that should be a good place to start from.
By default Threads are not implemented in PHP, and according to your phpinfo it does not seem to be loaded. Check out the PHP manual on how to set-up/configure the module.
Installed PEAR and followed the directions on http://www.phpunit.de/manual/current/en/installation.html:
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit.
Then, I created the test:
<?php
# error reporting
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
# include TestRunner
require_once 'PHPUnit/TextUI/TestRunner.php';
# our test class
class ExampleTest extends PHPUnit_Framework_TestCase
{
public function testOne()
{
$this->assertTrue(FALSE);
}
}
# run the test
$suite = new PHPUnit_Framework_TestSuite('ExampleTest');
PHPUnit_TextUI_TestRunner::run($suite);
?>
I included the following in php.ini file and restarted Apache:
include_path = ".;C:\Program Files/wamp/bin/php/php5.3.8"
include_path = ".;C:\Program Files/wamp/bin/php/php5.3.8/pear"
include_path = ".;C:\Program Files/wamp/bin/php/php5.3.8/pear/PHPUnit"
I get Warning: require_once(PHPUnit/TextUI/TestRunner.php) [function.require-once]: failed to open stream: No such file or directory in ...
Why doesn't the include path work? Is it because there is a space in Program files?
Working in Windows XP and WAMP.
EDIT: I updated the path as suggested.
The output of echo ini_get('include_path'); before require_once call is:
.;C:\Program Files/wamp/bin/php/php5.3.8/pear
Also, removing the require_once command throws Fatal error: Class 'PHPUnit_Framework_TestCase' not found in...
By adding those three lines to the ini, the last one will override everything. Only use this one
include_path = ".;C:\Program Files\wamp\bin\php\php5.3.8\pear"
Edit: adding #Gordon comment. We need to keep \pear. Because inner pear libraries are assuming that pear already in the include path.
http://pear.php.net/manual/en/installation.checking.php#installation.checking.cli.modifyingphpini