Couchbase PHP Connect Hello World! on Mac - php

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.

Related

Blackfire profiling not working

So I followed these instructions for my vagrant box and everything seemed to go fine, I mean its running. It has been configured with its server id and server token.
I then installed the PHP Probe, as per the instructions on the same page and restarted apache2 when it was done. I then did composer require
blackfire/php-sdk and finally in my code I did:
$probe = $blackfire->createProbe();
// some PHP code you want to profile
$blackfire->endProbe($probe);
dd('End here.'); // Laravels die and dump function.
So as far as I know I did everything right. Then, in my console I did:
vagrant#scotchbox:/var/www$ php artisan fetch_eve_online_region_type_history_information
[Blackfire\Exception\ApiException]
401: while calling GET https://blackfire.io/api/v1/collab-tokens [context: NULL] [headers: array (
0 => 'Authorization: Basic xxxxxx=',
1 => 'X-Blackfire-User-Agent: Blackfire PHP SDK/1.0',
)]
// where xxxx is some kind of authentication token that looks different from what I gave as my server id and token.
uh .... Ok so the docs state if something goes wrong to check the logs:
vagrant#scotchbox:/var/www$ cat /var/log/blackfire/agent.log
vagrant#scotchbox:/var/www$
Theres nothing in the logs....
What am I doing wrong?
Not a real solution, but rather a workaround until we hear more about how to actually solve it.
I have added the client credentials manually directly in the code and it solved the issue for me:
$config = new \Blackfire\ClientConfiguration();
$config->setClientId('...your _client_ id...');
$config->setClientToken('...your _client_ token...');
$blackfire = new \Blackfire\Client($config);
The string that I saw in the error was Authorization: Basic Og== and Og== is just a base64-encoded string :, which hints that username/password (or id/token in this case?) automatic lookup failed and authorization is impossible. That's why providing the details manually works around it.
A little bit late but maybe someone will need it in the future.
Adding the HOME environment variable to apache's vhost file so blackfire finds ~/.blackfire.ini solves it.
<VirtualHost hostname:80>
...
SetEnv HOME /Users/me #i'm running macOS, on linux would be /home/me
...
</VirtualHost>
consider that your probe configuration is correct (server_id & server_tokens) and you can profile from the browser , for using PHP SDK (phpunit integration with blackfire) you have to configure the client side :
apt-get install blackfire-agent
blackfire config you will prompt for BLACKFIRE_CLIENT_ID and BLACKFIRE_CLIENT_TOKEN .
you can also login to this api/v1/collab-tokens to test your client credentials username=>BLACKFIRE_CLIENT_ID , password=>BLACKFIRE_CLIENT_TOKEN
the config file location for the client : /root/.blackfire.ini

How to execute xpdf (pdftotext.exe) on shared drive?

im trying to parse pdf to text via PHP and XPDF (pdftotext.exe). On my localhost everythings works well, but when im trying to move everything on server, im getting into troubles.
First of all i checked some settings on server and safe_mode is off, exec is not disabled and permissions are rwxrwxrwx.
Then im trying this
$command = "\\\\149.223.22.11\\cae\\04_Knowledge-base\\tools\\pdftotext.exe -enc UTF-8 ". $fileName . " \\\\149.223.22.11\\cae\\04_Knowledge-base\\output.txt";
$result = exec($command,$output,$args);
echo shell_exec($command);
which isnt working. When i look into $result, $output, are empty, but $args returns 1 which coresponds to Incorrect function by this document windows system error codes
Whole command looks like \\149.223.22.11\cae\04_Knowledge-base\tools\pdftotext.exe -enc UTF-8 \\149.223.22.11\cae\04_Knowledge-base\testpdf\04_egerland_final_paper.pdf \\149.223.22.11\cae\04_Knowledge-base\output.txt and when is dirrectly inputed into commandline, its working.
So im a bit out of ideas. Have someone any hint?
edit 20160201 - aditional trying
So i made aditional tests and when im trying to run similar command with exec from localhost (target .exe file, input and output file is in same location, only im using localhost not server) its working. Im now checking differences in server settings. So can here be problem, that localhosts Server Api is Apache 2.0 Handler and server is CGI/FASTCGI?
So it was all mistake on my side. I badly checked IIS permissions and forgot to assign user to virtual directory which i wana to access. So my only advice and more wisdom from this is to double (maybe triple) check if you have all permissions set correctly.

Using Cassandra PDO Driver on Windows

Is there any way to have Cassandra PDO at Windows with Wamp?
This is for development purposes I don't want to install Linux and change all the environment.
https://code.google.com/a/apache-extras.org/p/cassandra-pdo/
I'm using Windows 7 (64 Bit), Wamp 2.5, PHP 5.5.
OK, here's what I found out:
1) It's totally possible
2) The docs that appear in the first google search results are a bit obsolete
Start by downloading the latest Datastax Community Cassandra here:
http://planetcassandra.org/cassandra/
Install & setup properly. In fact, most of the configuration is done by the installer, you just have to edit the apache-cassandra/conf/cassandra.yaml file to find all paths to /var/lib... and change those into something like d:/cassandra/... That includes "commitlog", "data", "saved_caches". Restart the Cassandra service, examine the logs. Mine shown no problem. The OpsCenter at ...:8888/opscenter/index.html was working fine, showing one node online.
Now, the PHP part.
There's a sneaky thing called Thrift. From what I've learned today (I first heard about Cassandra and Thrift yesterday), it's a way describe a binary protocol of connecting to some online service, in this case, to Cassandra. It will basically generate PHP files that will provide all the connectivity you need from PHP itself (no extensions needed).
You will need:
1) The Thrift PHP libs
2) The .exe Thrift compiler
Both can be downloaded here:
https://thrift.apache.org/download
Then use the following command to compile PHP files that will act as a "driver" to connect your PHP applications to Cassandra:
thrift --gen php D:\DataStaxCommunity\apache-cassandra\interface\cassandra.thrift
Put the result in some PHP include_path folder.
Also, find the PHP Thrift libs (in the libs archive from the same download page) and put those in a folder accessible to your script (e.g. include_path or the project folder).
Refer this page:
thrift.apache.org/lib/php
I guess that should help!
I have same problem as you, but when i tried this method, it works correctly for me.
Reference link
Here is a code example, very easy to understand :
<?php
require_once 'Cassandra/Cassandra.php';
$o_cassandra = new Cassandra();
$s_server_host = '127.0.0.1'; // Localhost
$i_server_port = 9042;
$s_server_username = ''; // We don't use username
$s_server_password = ''; // We don't use password
$s_server_keyspace = 'cassandra_tests';
$o_cassandra->connect($s_server_host, $s_server_username, $s_server_password, $s_server_keyspace, $i_server_port);
$s_cql = "CREATE TABLE carles_test_table (s_thekey text, s_column1 text, s_column2 text,PRIMARY KEY (s_thekey));";
$st_results = $o_cassandra->query($s_cql);

Extension php_win32service installs the service, but the service won't start up (hangs)

I am trying to setup a PHP web application on a Windows Server 2008 SP1 machine. We have this application running correctly on a Windows Server 2003, but are now unable to get the Windows services built with php_win32service PHP extension starting up correctly.
Here are the relevant sections of the PHP code. Here is the section that does the install and uninstall:
if ($argv[1] == 'install') {
win32_create_service(array(
'service' => $service_name,
'display' => $service_name,
'params' => '"'. __FILE__ . '"' . ' run'));
exit;
}
else if ($argv[1] == 'uninstall') {
win32_delete_service($service_name);
exit;
}
else if ($argv[1] != 'run') {
die("Invalid arguments");
}
win32_start_service_ctrl_dispatcher($service_name);
And here is the main loop:
while (1) {
switch (win32_get_last_control_message()) {
case WIN32_SERVICE_CONTROL_INTERROGATE: win32_set_service_status(WIN32_SERVICE_RUNNING); break; // Respond with status
case WIN32_SERVICE_CONTROL_STOP: win32_set_service_status(WIN32_SERVICE_STOPPED); exit; // Terminate script
}
processQueue();
usleep(500000);
}
The install and uninstall work as long as I run cmd as administrator. If I launch cmd under the account that I use to login to the server then the service is not created win32_create_service. I can also run the script with the run parameter from the command line and it runs correctly, but when I try start the service it just hangs on with the Starting message and never goes into Started state.
I think this issue has something to do with the rights of the LocalSystem account on the machine, but I do not know what rights are needed to get this to work properly. I also do not know how I can debug this and find out what error/issue is occurring with the WIN32_SERVICE_CONTROL_INTERROGATE, especially as I do not have rights on this server to make changes to security settings. Any changes that I need made to security settings I need to communicate to the network administrator so that he can perform the changes. Can anyone offer any help with debugging or resolving this issue?
UPDATE:
This issue only seems to occur in the 64-bit version of PHP. It seems that the 64-bit compile of php_win32service runs into some sort of problem when trying to start the service. I removed the 64-bit versions of PHP and 'php_win32service' and replaced them with the 32-bit versions. The service then started correctly.
Have you tried with NetworkService account? Other way is creating own service account. Do you communicate outside the server? Maybe firewall?
Ps. the network service account has a default password (system known)
Note that this account does not have a password, so any password information that you provide in this call is ignored.
http://msdn.microsoft.com/nl-nl/library/windows/desktop/ms684272(v=vs.85).aspx
Updated Answer:
I am now convinced that this issue arises when you update or downgrade PHP to a different version, but fail to remove and recreate the services using the php_win32service for the newly installed version of PHP. This was mentioned as an aside in my old answer, but after encountering the same thing on another server and resolving it by removing and recreating the service entries, I am convinced that this is the true cause of this issue and that is not a bug in PHP.
Old Answer:
I encountered this issue again when I tried to update PHP on a Windows Server 2008 machine from 5.3 to 5.6. From the testing that I have done I have concluded that php_win32service.dll extension works correctly for PHP 5.3, but not from 5.4 upwards. From 5.4 there seems to be a bug whereby the function win32_get_last_control_message always returns 0 rather than a valid status.
I finally got a clue to what was going on from a post made over here:
http://enlinea.creaelicita.cl/guia/function.win32-set-service-status.html
So, if you have code such as this:
while (1) {
switch (win32_get_last_control_message()) {
case WIN32_SERVICE_CONTROL_INTERROGATE: win32_set_service_status(WIN32_SERVICE_RUNNING); break; // Respond with status
case WIN32_SERVICE_CONTROL_STOP: win32_set_service_status(WIN32_SERVICE_STOPPED); exit; // Terminate script
}
usleep(3000000);
// Main script goes here
processQueue();
}
then
win32_set_service_status(WIN32_SERVICE_RUNNING);
will never get called, because win32_get_last_control_message never gets the value of 4 (WIN32_SERVICE_CONTROL_INTERROGATE).
A workaround which I use is to add a default case to the switch statement that sets the service status. Like this:
switch (win32_get_last_control_message()) {
case WIN32_SERVICE_CONTROL_INTERROGATE: win32_set_service_status(WIN32_SERVICE_RUNNING); break; // Respond with status
case WIN32_SERVICE_CONTROL_STOP: win32_set_service_status(WIN32_SERVICE_STOPPED); exit; // Terminate script
default: win32_set_service_status(WIN32_SERVICE_RUNNING);
}
As an aside, I also found that this issue occurred if I upgraded to PHP 5.4 and did not recreate the service entries before trying to start them. So besides applying the above workaround, remember to first uninstall the windows service in question and reinstall it from your PHP script.

php access network path under windows

within PHP (XAMPP) installed on a Windows XP Computer Im trying to read a dir which exists on a local network server. Im using is_dir() to check whether it is a dir that I can read.
In Windows Explorer I type \\\server\dir and that dir is being shown.
When I map a network drive a can access it with z:\dir as well.
In PHP I have that script:
<?php if( is_dir($dir){ echo 'success' } ) ?>
For $dir I tried:
/server/dir
//server/dir
\server\dir
\\server\dir
\\\\server\\dir
and
z:\dir
z:\\dir
z:/dir
z://dir
But I never get success?
Any idea?
thx
I solved it by changing some stuff in the registry of the server as explained in the last answer of this discussion:
http://bugs.php.net/bug.php?id=25805
Thanks to VolkerK and Gumbo anyway!
I love stackoverflow and their great people who help you so incredibly fast!!
EDIT (taken from php.net):
The service has limited access to network resources, such as shares
and pipes, because it has no credentials and must connect using a null
session. The following registry key contains the NullSessionPipes and
NullSessionShares values, which are used to specify the pipes and
shares to which null sessions may connect:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
Alternatively, you could add the REG_DWORD value
RestrictNullSessAccess to the key and set it to 0 to allow all null
sessions to access all pipes and shares created on that machine.`
add RestrictNullSessAccess=0 to your registery.
You probably let xampp install apache as service and run the php scripts trough this apache. And the apache service (running as localsystem) is not allowed to access the network the way your user account is.
A service that runs in the context of the LocalSystem account inherits the security context of the SCM. The user SID is created from the SECURITY_LOCAL_SYSTEM_RID value. The account is not associated with any logged-on user account.
This has several implications:
...
* The service presents the computer's credentials to remote servers.
...
You can test this by starting the apache as console application (apache_start.bat in the xampp directory should do that) and run the script again. You can use both forward and backward slashes in the unc path. I'd suggest using //server/share since php doesn't care about / in string literals.
<?php
$uncpath = '//server/dir';
$dh = opendir($uncpath);
echo "<pre>\n";
var_dump($dh, error_get_last());
echo "\n</pre>";
Try the file: URI scheme:
file://server/dir
file:///Z:/dir
The begin is always file://. The next path segment is the server. If it’s on your local machine, leave it blank (see second example). See also File URIs in Windows.
Yes, I know this is an old post, but I still found it, and if anyone else does...
On Windows, with newer servers, verify the SMB is installed and enabled on the target machine.

Categories