Configuring the SublimeLinter Plugin to use PHP - php

I installed the SublimeLinter plugin for Sumblime-text-2 in Ubuntu 12.04.
The PHP linting does not work. After an exhaustive search on the internet, I found out that I have to give the path to PHP in the sublimeLinter settings as below:
"sublimelinter_executable_map":
{
"php":"/usr/share/php"
},
This was the path in the line include_path I found in the phpInfo(). But it does not work.
I tried escaping the special characters, and other paths like /usr/share/php5, /usr/lib/php5, but nothing seems to work.
Can anyone help with the correct configuration, so that I can get the linter functionality to work?
Note: There has been a previous unanswered question here. I thought maybe I should ask it again, in a little more detail.
UPDATE: The original question has been answered and solves this question as well.

1- Install node.js. Which, by the way, is pretty darn awesome in its own right.
2- Open up Sublime Text, and close all open files.
3- Head to Preferences->Package Settings->SublimeLinter->Settings – User (it will be empty if you haven’t messed with it before), and insert the following:
{
"sublimelinter_executable_map":
{
"javascript":"C:/Program Files/nodejs/node.exe",
"css":"C:/Program Files/nodejs/node.exe",
"php":"C:/wamp/bin/php/php5.4.3/php.exe"
}
}
This is also where you’d put paths to, say, php for linting. Make sure you get the path to node correct – this is the default location on a Windows 7 install. Save the file, close the file, and restart Sublime Text.
sources: http://fuzzytolerance.info/blog/2012/05/14/2012-05-15-getting-sublimelinter-running-on-windows/

For ubuntu system type in terminal:
which php
and use the result in your php path (Preferences->Package Settings->SublimeLinter->Settings -User).
In my case it's:
{
"sublimelinter_executable_map": {
"php": "/usr/bin/php"
}
}

php.exe file path on Windows 7 didn't do the trick for me, while
php-win.exe did:
{
"sublimelinter_executable_map":
{
"php":"C:/php/php-win.exe"
}
}

php-win.exe file path on Windows 7 didn't do the trick for me!!!
"sublimelinter_executable_map":
{
"javascript":"C:/Program Files/nodejs/node.exe",
"php":"C:/xampp/php/php-win.exe",
"css":"C:/Program Files/nodejs/node.exe"
}

Related

Nothing has worked to code PHP in Visual Studio Code via Windows 10

I am taking a Udemy class for WordPress. I can create a function just fine. However, when I started using the variables and array it will not work. I get a message saying there is no "php.validate.executablePath" and "php.executablePath" via settings.json.
So I downloaded the zip file of PHP 7.3 (7.3.17) VC15 x64 Non Thread Safe and extracted it to C:\php7.3. I then added the path to the settings.json: "php.validate.executablePath": "C:\php7.3\php.exe", "php.executablePath": "C:\php7.3\php.exe"
I then restarted my VSC and nothing happened. I even restarted my computer. The notification never popped up again but I still cannot run PHP. In replace of the \, I used one \, then one /, then two / but it did not change anything. I looked this issue up - found others who had the same issue - and have not found anything that has worked for me so far.
I also tried downloading the xampp but there was an issue at port 443. That's when I downloaded the PHP file directly and uninstalled xampp.
EDIT: Do I have to have something like xampp or wamp to execute the PHP? If so, I would just need to figure out how to fix that error.
Here is a screenshot of the code I used: http://prntscr.com/sahb1f
Here is a screenshot of the settings.json: http://prntscr.com/sahbk0
I am on Windows 10 x64. A tool extension for VSC costs money, which I do not want to spend.
Any help?
Thanks!
You are missing the echo in front of the $names[0] array element access.
change your line to this <p>Hi, my name is <?php echo $names[0]; ?></p> and it should work however your error to do with executablePath might be because of something else.

can't load HHVM extension (dynamic)

I'm writing an C++ extension (dynamic load) for HHVM. I followed the instructions on this page:
https://github.com/facebook/hhvm/wiki/Extension-API
which links to an example in:
https://github.com/hhvm/extension-example
I compiled hhvm on Ubuntu 14.04 which took nearly 2 hours. Then I also compiled the example extension.
My question is, how to load it?
The information on the internet seems to be out-of-date or inconsistent.
Anyway, I first tried to create /etc/hhvm/config.hdf with these lines:
DynamicExtensions {
example = /path/to/example.so
}
Nothing happened. And then I saw this:
From: http:// hhvm.com/blog/4349/hhvm-3-0-0
We are moving from .hdf config files to .ini. The default one lives in
/etc/hhvm/php.ini. We don’t support all the old options yet, so you
can still use config.hdf for now, but be ready for it to die in the
next release. All of your favorite options will go from Foo { BarBaz =
True } to hhvm.foo.bar_baz = true.
OK, then I tried to put lines in /etc/hhvm/php.ini or /etc/hhvm/server.ini instead of .hdf
hhvm.dynamic_extensions.example = /path/to/example.so
But with no luck, nothing worked. I need more info/docs.
So, is there anyone know what happen? or if the HHVM team from Facebook see this post, could you please help me?
I see that you've managed to get it to load, so I'll just focus on not being able to find the function.
Shortly after the release of HHVM 3.0, the way that PHP files are loaded from extensions changed. Basically, the first four characters of the name of the file are stripped when embedding it, since it's expected to be ext_name.php. The example extension hadn't been updated for this change until last night.
The change is rather simple. Just rename example.php to ext_example.php and, in config.cmake change HHVM_SYSTEMLIB(example example.php) to HHVM_SYSTEMLIB(example ext_example.php) then re-run cmake . && make.
You can see the committed change (which does exactly this) here

how to convert with princeXML and PHP

I followed the directions on the readme file but I didn't get any errors nor any output or anything written to the log file.
so, what is the right way of converting and HTML file to PDF with prince, thank you in advance.
ini_set('display_errors', '1');
error_reporting(-1);
require 'prince.php';
$exepath='/Users/agk/Desktop/prince/bin/prince';
$prince= new Prince($exepath);
if(!$prince) die("Prince instantiation failed");
$prince->setHTML(TRUE);
$prince->setLog('prince.log');
$xmlPath='/Applications/MAMP/htdocs/test/newhtml.html';
$msgs= array();
$convert=$prince->convert_file($xmlPath, $msgs);
if(!$convert)
{
echo 'nothing converted';
var_dump($msgs);
}
I notice you are using MAMP - and this is where I hit the same issue - and here's how I fixed it.
I managed to find an answer elsewhere on SO relating to running shell commands via PHP on MAMP, so will share this.
The problem is that the DYLD_LIBRARY_PATH is set in MAMP, and the shell/shell_exec command in PHP is looking elsewhere.
As explained in the original post, this might not be the best fix but it has me up and running for now - and the alternative suggestions there didn't work for me.
So, try this:
Open the /Applications/MAMP/Library/bin/envvars file and comment the following lines as below:
#DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
#export DYLD_LIBRARY_PATH
then restart Apache
It might mess up other MAMP settings, but I can live with that for now, as I need this to work locally on my Mac for testing before I load it all on a live Linux server.
Hope this helps.

How to get pthreads working in PHP?

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).

PHP Wamp is not finding a file which exists

I'm having a critical issue where my WAMP installation for PHP 5.3.0 is not finding a file which exists within my computer. Does anyone know anything about this? Possibly a PHP Bug?
Any help would be much appreciated.
Here is the variable which creates the file:
$baseNewsUrl = "C:/reviews/reviews/$platform/$fullname";
And here is the code which grabs the contents:
if(is_file($baseNewsUrl)){
$contents = file_get_contents($baseNewsUrl);
} else {
echo "File not found. " . "\r\n";
continue;
}
Here is the output of $baseNewsUrl: C:/reviews/reviews/GBA/r20107_GBA.htm
And the file does exist.
Check that the entire path leading up to your file is readable by the user PHP is running as (if you are using IIS, this might be something like "Network Service," although I am not particularly experienced with PHP on Windows). Also, check whether the INI directives "open_basedir" or perhaps "safe_mode" are set--these would give PHP self-imposed limits on which files are accessible.
Do a var_dump (not an echo) on your variable.
var_dump($baseNewsUrl);
and look at the actual contents. You may have some invisible garbage characters in there that's preventing Windows if you're doing this in a browser to make sure there's no empty tags (or other browser-render-invisible) characters.
If that doesn't reveal anything, remove the is_file check and try to open the file with file_get_contents (or any file related function) and var_dump it's contents. You'll either open the file, or PHP will spit out an error/warning/notice (either to your browser or to your error log) that should let you know why it can't open the file.
I'm gonna say this, and it very well might not be your problem but it is a recurring one for me. If you use skype on your computer, it has a somewhat known compatibility issue with WAMP. It cause's WAMP to be unstable, not load files properly.. everything.
on windows
$baseNewsUrl = "C:\\reviews\\reviews\\$platform\\$fullname";
It's due to Windows Vista and WAMP.

Categories