I use Netbeans on my windows desktop to debug a PHP web application remotely running on a Linux server with xdebug installed. One missing feature that constantly bothers me is: I can not view the content of static variables in a class. Often I have to resort to the "print" or "var_dump" method to find the variable content, which is very inconvenient.
Does anyone know how to config it properly? I failed to find any related settings in the Netbeans menu. My Netbeans version is 7.0.1 running on Windows 7, and my remote server is CentOS 5.4 running PHP 5.2 with the latest xdebug module.
Well, it seems fixed (more like "added") in xdebug 2.1.3, but I can't test it yet, as there aren't DLL's for my setup (VC9 only; hope there'll be VC6, too). Give it a go.
Until then, use watches (another "great" method). Using the example in the link (and I'm reffering to NetBeans here):
class testclass {
static private $name;
static public function show_name() {
//do something with $name
self::$name = "Sir John\n" . self::$name;
return self::$name;
}
}
echo testclass::show_name();
Put a breakpoint at the return statement.
Start debugger
If you don't see the "Watches" tab, go to menu -> Windows -> Debugging -> Watches
Go to Watches tab, right-click, New Watch. Type self::$name as the expression. (for regular vars, use $varName as expression). This was the tricky part. I didn't know about this until now.
Run code.
If you control-click the variable, does it not take you to the variable definition automatically? This is the behavior I have.
Related
I am using php version 7 and defined a class that extend Thread class but when I run My Program that give me Class 'Thread' not found error.I searched and I found out I must copy pthreadVC2.dll in apache and system32 folders and copy php_pthreads.dll in php/ext and system32 folders and add extension=php_pthreads.dll to php.ini .I did all these works but I get that error again.php_pthreads.dll and pthreadVC2.dll version is 14
<?php
class exampleThread extends Thread
{
var $Mobile;
var $code;
public function __construct($Mobile, $code)
{
$this->Mobile = $Mobile;
$this->code = $code;
}
public function run()
{
}
};
?>
The pthreads extension cannot be used in a web server environment. It is only available in the CLI.
Whatever you're trying to do, you'll need to come up with another way of doing it.
As stated in the answer from duskwuff, the pthreads extension cannot be used in a web server environment.
We were playing around for about 1 week and unfortunately had to realize that running it in the CLI version leads to too many issues once it becomes too complicated --> we stopped and removed pthreads from our environment.
What I can suggest you:
Due to the fact we still need a multi-threaded functionality we were checking several methods and ended up using curl multi functions.
With curl multi functions you achieve a full multi-threading execution - and especially in our case - when you got lot of cores [we have 48] you can indeed use all of them when you spawn your tasks with curl...
The PHP curl multi exec documentation is very poor. I refer to this thread where you get additional information.
I installed the Couchbase Server and its PHP SDK through brew install libcouchbase on Mac. The server admin console is running/working fine on http://127.0.0.1:8091/. I added a hello.php file with the below code in /Library/WebServer/Documents/hello.php.
<?php
$cb = #new Couchbase("http://127.0.0.1:8091/",'username','password');
if($cb->getResultCode() != COUCHBASE_SUCCESS){
throw Exception('Cannot connect to couchbase!');
} else {
echo "Hello World!";
}
When I go to http://127.0.0.1:8091/hello.php, I get an error saying Not found.. What is the problem?
When I go to http://127.0.0.1:8091/hello.php, I get the below error
Not found.. What is the problem?
You are going to the wrong port. Port 8091 is the Couchbase Server Console interface. It looks like you are trying to deploy your hello.php script using the Apache server shipped with OS X which uses the default http port (80). The script is also located in the wrong folder. I believe /Library/WebServer/Documents/ is for static content only.
Given the problem you have ran into it make me suspect that you are trying to learn too many new things at once. You should try running the script outside of a Apache first and get it working there.
php hello.php
It is also worth pointing out that you are using the older 1.X version of the Couchbase PHP SDK, you will want to use the new 2.X version.
I assume you've anonymized the code above, but be sure in place of where you have 'username' you have the bucket name and similarly for the bucket password or empty string if no password. Also, check the docs as the connect string you're using is not necessarily the preferred..
Note for debugging these kinds of things you can set LCB_LOGLEVEL to a higher level as mentioned in the documentation. The way you set an envvar varies based on how you're deploying PHP, but you can easily just test it at the command line.
I am using wampserver to test & run wordpress code in my local computer. In order to run pthread, I have followed the following steps:
1) I got the pthread zip file from http://windows.php.net/downloads/pecl/releases/pthreads/0.44/
(My machine has php 5.3.13 and downloaded the php_pthreads-0.44-5.3-ts-vc9-x86.zip file from the above link).
2) Extracted the zip file. Moved the php_pthreads.dll to the C:\wamp\bin\php\php5.3.13\ext directory.
3) Moved pthreadVC2.dll to the C:\wamp\bin\php\php5.3.13 directory.
4) Then Opened C:\wamp\bin\php\php5.3.13\php.ini and added the code extension=php_pthreads.dll at the begining of the file.
But when I try to run the following code:
<?php
class My extends Thread {
public function run() {
printf("%s is Thread #%lu\n", __CLASS__, $this->getThreadId());
}
}
$my = new My();
$my->start();
?>
It gives me the following error:
Fatal error: Class 'Thread' not found in C:\wamp\www\wp-admin\includes\post.php on line 2
Can you please tell me how to install pthreads in my computer to use with php? and do I have to install any other software?
I've noticed that wampserver has php.ini in two separate places. One place is in the /wamp/bin/php/php5... directory, and the other place is in the /wamp/bin/apache/apache.../bin directory (where "..." represents version numbers). The two files need to be identical, because apparently both are loaded at different times by the overall wampserver boot-up procedure.
(Note I only discovered this recently, and may be well "behind the curve" of doing fancy things with wampserver --maybe everyone else has been dealing with both files for a long time. So I don't know if this simple thing will fix your problem; I came here looking for info, myself, regarding doing some multi-threading stuff. :)
One other thing. According to this page: www.php.net/manual/en/pthreads.requirements.php
PHP has to be compiled with "--enable-zts" in order for pthreads stuff to work. I have not been able to find any evidence that the PHP part of wampserver was compiled that way.
(months later)
Having decided I didn't really immediately need to do any threading stuff, I went on to do other things, until the need actually arose. I now can say that the version of PHP compiled into WampServer does support the "pthread" extension, although some set-up work is needed, first. The instructions I saw mentioned putting a couple of .dll files (after a download and unZip) into certain places, but that didn't work for me. Copying them to the \Windows\System32 directory did work. (Putting them into the \apache...\bin directory also works; there are some other php .dll files in there.)
After that, much like what you did, it is necessary to define a "class" that extends the "Thread" class, in order to actually do something in another thread. The "run()" function in the Thread class is "abstract", and needs to be "realized" as an actual function in the extended class. Then the "new" operator can create an "instance", an object of that specified class, for actual use. Here's the class that I needed:
//Purpose: Use another thread to run the code in another php file, after a delay
class xT extends Thread
{ var $fil, $tim;
function savWhatWhen($f="", $t=0)
{ $this->fil = $f; //save What, file to process
$this->tim = $t; //save When, delay before processing file
return;
}
function run()
{ ini_set('max_execution_time', 600); //600 seconds = 10 minutes
sleep($this->tim); //do a delay; beware of max-exec-time!
include($this->fil); //load file-to-process, and process it
return;
} }
That "savWhatWhen()" function was created specifically for this extension of the basic Thread class. Here's some code for using that class:
$TH = new xT(); //prepare a separate Thread
$TH->savWhatWhen("d:/wamp/myscripts/test.php", 45);//file-name and delay time
$TH->start(); //after delay, process file
//the code that does this can terminate, while OTHER thread is doing a delay
Note for anyone copying this code, you might need to make sure your "open_basedir" setting in the php.ini allows access to the specified file.
More months later: With lots of things being worked on, I haven't put a lot of time into using my pthread object. I did encounter a peculiarity that makes me wonder about whether or not I can actually use pthreads the way I had hoped. Here is what I have observed:
1. An initial php file is called by AJAX, to do something.
2. The PHP processor on the Web Server does that thing.
3. Various data is supposed to be echoed to the browser.
4. The initial php file calls for the creation of another thread, and terminates.
5. The browser does not yet receive the echoed data!
6. The PHP processor on the Web Server does the work delegated to the second thread.
7. When the second thread terminates, NOW the browser receives the echoed data!
At this writing I'm thinking I missed something. Perhaps I need to do some forceful "flush" stuff when the first thread ends, so that the browser can receive the echoed data and the user can do things while the PHP processor on the server is also doing things.
Check for extension_dir = "ext" in you php.ini file. Make sure it points to the folder where your extensions reside and make sure it's not commented (it has a semicolon ; in front of it)
You have to add a require_once() with the path of the Thread class before extending it (if your framework don't use an autoload class system)
I've encountered the same problem, in my case placing the pthreadVC2.dll in
..wamp\bin\apache\Apache2.4.4\bin
(instead of ..\wamp\bin\php\php5.4.16 as the guide in php.net instructs) solved the problem
Wamp server has a separate php.ini config file for the browser and for the cli.
To use the pthreads module in the browser with WAMP Server you need to copy the "pthreadVC2.dll" into the apache "bin" directory also.
You should now have he "pthreadVC2.dll" in both of these folders (if installed in default location):
C:\wamp\bin\php\php[x.x.xx]\bin
C:\wamp\bin\apache\apache[x.x.x]\bin
You will also need to update the php.ini file within the php bin directory AND the apache bin directory to include:
extension=php_pthreads.dll
This now means you can use pthreads in the browser and in the cli with wamp server
After encountering the same problem, I noticed that I have installed the wrong Pthread version (3.1.6 : requires PHP7+) which wasn't compatible with my PHP version (5.5.12). Solved the problem with Pthread version 0.0.44. An earlier version should probably work well.
Here is the download page for Pthread and the installation page. Be careful about the both php.ini location as mentioned above (Apache folder=for Browser, PHP folder=CLI).
I do have a PHP script, which is not an extension for Typo3. Now I would like to delete the whole Cache of Typo3 out of this script. How is that possible?
install the TYPO3 Extension cleartypo3cache
create a tool and a keyboard shortcut in PhpStorm 4 to trigger cleartypo3cache
SSH access with passwordless pubkey authentication when pushing to a remote host.
Install Extension "cleartypo3cache" and create the BE user "_cli_cleartypo3cache" and add the following TSconfig:
options.clearCache.all=1
options.clearCache.pages=1
Now test if cache is cleared:
$ cd /path/tp/typo3-site/
$ php typo3/cli_dispatch.phpsh cleartypo3cache all
If your webserver is on localhost, you are lucky because you don't need this shell script. If your webserver is on a remote host, you need an additional wrapper script. This is because PhpStorm does not provide an environment variable for the remote host directory. You have to set this directory statically for each project in the wrapper script:
#!/bin/sh
TYPO3_SITE_PATH="/path/to/typo3-site"
USER="alice"
HOST="example.com"
/usr/bin/ssh $USER#$HOST '/usr/bin/php $TYPO3_SITE_PATH/typo3/cli_dispatch.phpsh cleartypo3cache all'
Save this file in your project file directory into .idea/clear-typo3-cache.sh and make it executable:
$ chmod 755 .idea/clear-typo3-cache.sh
PhpStorm External Tools
You need to create an "external tool" in PhpStorm to be able to clear cache.
Go to PhpStorm-->Settings-->External Tools-->Add...
Give your tool a name and a group, e.g. "Deployment" -> "Clear TYPO3 Cache"
Deactivate checkbox "Open Console" and "Menu->Search Results"
Remote host scenario
Add the following line to "Programm:"
$ProjectFileDir$/.idea/clear-typo3-cache.sh
Localhost scenario
Add this line to "Program:"
$PhpExecutable$
Add this line to "Parameters:"
$ProjectFileDir$/typo3/cli_dispatch.phpsh cleartypo3cache all
You need to have a PHP interpreter configured in PhpStorm-->Settings-->PHP to use $PhpExecutable$. Alternatively you can use /usr/bin/php
(source: t3node.com)
PhpStorm Keymap
I suggest to use the same key binding as you use for saving or remote host uploading:
Go to PhpStorm-->Settings-->Keymap
For remote host scenario, navigate to: Main menu-->Tools-->Deployment-->Upload to Default Server. Notice the existing shortcut. If you don't have one for that, create a new one (I use ALT+SHIFT+U)
For the localhost scenario, just use Ctrl+S (Main menu-->File-->Save All).
Now navigate to the External Tool you have created (e.g. External Tools-->Deployment->Clear TYPO3 Cache)
Right click "Add Keyboard Shortcut"
Create the particular shortcut in "First Stroke"
Now PhpStorm will warn you that the shortcut is already in use for a different command. That's fine, it's exactly what we want to have.
That's it. Your TYPO3 caches are always cleared when you hit save or upload on your keyboard.
adapted from t3node
I found the solution myself and its actually pretty easy. I took a look into the class.t3lib_tcemain.php in the t3lib folder. There you've got the necessary commands to clear the cache. It also checks, if you have the cachingframework enabled. If so, you need to truncate a few other tables as well (Starts with cachingframework_cache_)
It is basically:
<?php
require_once('./typo3conf/localconf.php');
$conn = mysql_connect($typo_db_host, $typo_db_username, $typo_db_password);
mysql_select_db($typo_db);
// Clear Cache here
mysql_query("TRUNCATE cache_treelist;");
mysql_query("TRUNCATE cache_pagesection;");
mysql_query("TRUNCATE cache_hash;");
mysql_query("TRUNCATE cache_pages;");
if($handle = opendir('./typo3conf')) {
while (false !== ($file = readdir($handle))) {
if(strpos($file, 'temp_CACHED_')!==false) {
unlink('./typo3conf/'.$file);
}
}
closedir($handle);
}
?>
TYPO3 >= 7
From TYPO3 7 on you can install Helmut Hummels Extension typo3_console.
Then you can clear the cache like (for composer installations):
./vendor/bin/typo3cms cache:flush
https://extensions.typo3.org/extension/typo3_console/
https://github.com/TYPO3-Console/TYPO3-Console
TYPO3 6.x
first initialize the Service in your Class
/**
* #var Tx_Extbase_Service_CacheService
*/
protected $cacheService;
/**
* #param Tx_Extbase_Service_CacheService $cacheService
* #return void
*/
public function injectCacheService(Tx_Extbase_Service_CacheService $cacheService) {
$this->cacheService = $cacheService;
}
in your function just call
$this->cacheService->clearPageCache($pids);
while $pids is an integer (for single page) or array of integers (multiple pages)
see: http://typo3.org/api/typo3cms/class_t_y_p_o3_1_1_c_m_s_1_1_extbase_1_1_service_1_1_cache_service.html
In TYPO3 since 4.5 (I think) its a static method so you have just to call
Tx_Extbase_Utility_Cache::clearPageCache($pids);
in your controller.
Found it here: http://www.phpkode.com/source/p/typo-cms/typo3_src+dummy-4.6.5/typo3/sysext/extbase/Classes/MVC/Controller/ActionController.php
In FLOW3 there is a possibility to do such stuff, as far as I know with TYPO3 v.4.x You have no such default CLI option, so You should use or You own script, or use such extensions as cleartypo3cache or Cli Cleaner.
Also I made a bash script to clean cache tables of Your dB : https://gist.github.com/fedir/5162747
in typo3 6.x extbase its simple.
Edit : clearPageCache is not static then you need to create object of CacheService
TYPO3\CMS\Extbase\Service\CacheService::clearPageCache(pageUid);
I have a live server which I want to occasionally use for testing purposes. I only have access to FTP and some basic administration tools there.
Reading the documentation for dl() gives me hope I can load xDebug dynamically even though I can't add it to the loaded extension list. I have little idea how though.
Question: How to obtain the appropriate compiled version of xdebug (or any other PHP extension) which would be ready to be used with dl()?
BTW, AFAIK the OS is CentOS 4 in my case, but I'd appreciate a broader answer too - for future reference.
xdebug is a zend-engine extension and thus cant be loaded dynamically.
You can try with xhprof instead. That should be possible to load at run time (I haven't much experience with it though, so i cant offer you specifics)
I usually use php_uname to determine the server OS
function os_check() {
$os_string = php_uname('s');
if (strpos(strtoupper($os_string), 'WIN')!==false) {
return 'windows';
} else {
return 'linux';
}
Such information is in various places in phpInfo()
<?php
phpinfo();
?>