So I have a huge list of text files inside a folder that I must process using a PHP script, and if processing is successful, I need to discard the file. However I only want to attempt 3 times each file, at most. If after the 3rd attempt it fails, I'll discard the file regardless.
So after doing some research I learned about Linux extended file attributes, and that seemed to be a viable way of keeping a counter in each file by means of an extended attribute.
Further research told me PHP supports this with a Pear package named xattr. I then installed the required libattr extension by running this command line (This is an Ubuntu 12.04 system by the way):
sudo apt-get install libattr1-dev
That worked fine. I then installed Pear xattr with:
sudo pecl -v install xattr
Which also succeeded and it indicated I had to add this line to php.ini:
extension=xattr.so
Which I also did and then restarted Apache. But when I attempted to use any of the xattr commands in PHP I always get this:
Call to undefined function xattr_supported()...
I checked phpinfo() and it indicates xattr support is enabled....
So what am I missing here? Shouldn't xattr_supported() at least return a boolean indicating whether extended attributes are supported by the file system or not? Or, is there any other way I can write random data to a plain text file without altering its contents?
Thanks in advance.
Related
I have updated windows today and now when I use the command line and type PHP nothing returns. tried various PHP commands, nothing, not even an error or response. blank.
I had the correct path in the environment variables. Tried to change to another PHP version and even tried removing the path from environment variables but still returns empty!
It doesn't even say that "PHP" is not recognized although I removed the environment variable!!
I have no clue how to solve this.
If you are not passing extra parameters when you call it from command line, that´s how it supposed to work.
Try running:
php --help (to see all options from command line)
Also, to make sure it is running try to do this:
php -v (to check version)
php -F filename.php
The last one should run your php file.
I had the same challenge.
Here's a solution:
Use a standard terminal window (instead of Powershell).
Try php -v again.
IF you get an error mentioning VCRUNTIME140.dll
THEN you need to install run-time components that are required to run C++ applications built using Visual Studio 2015 here: https://www.microsoft.com/en-us/download/details.aspx?id=48145
is there a way to log all calls that to exec() PHP makes? Recording PHP file and line number, and target executable with arguments, for example.
Thanks
You've got a few options, none of them are great:
If you have PECL APD installed, you can use override_function().
If you have PECL runkit installed, you can use runkit_function_redefine().
If you have the ability to wrap all the code in question with a namespace (possibly via the auto_prepend_file setting), you can just define a new exec() function.
Enable safe_mode and put nothing but a wrapper script in safe_mode_exec_dir. The only thing people will be able to exec is that wrapper, which can log hits and then spawn the requested command.
If you're concerned about what is getting exec()'ed, your best bet is probably just to turn it off by adding it (and its brethren) to the disabled_functions list.
As a Linux beginner I'm currently a bit confused building my own PHP from source.
I have a Ubuntu with a LAMP-Stack where all packages comes from a Repository.
(PHP as FastCGI)
Now I'm trying to set up a second PHP-Version and actually it works well but I have a few questions.
First of all some specs:
Ubuntu 10.04 (I need this older Version)
PHP 5.3.2-1ubuntu4.2.5 (Repo)
For my own PHP-Version I use the following "./configure" parameters (Reduced to the essential):
--prefix=/opt/php5310
--with-config-file-path=/opt/php5310/etc
--with-config-file-scan-dir=/opt/php5310/conf.d
--with-libdir=lib64
--with-mysql=/usr/bin/mysql
...
First of all executing "sudo make test" show up a few failed tests (about 10-14). Unfortunately I can't find any information what I have to do or what excactly goes wrong but "sudo make install" works nevertheless.
Is it normal that not all tests passed?
Then I noticed (phpinfo) the "imagick" extension was not loaded.
Looking at the "extension_dir" shows why.
On the Repo-Version:
extension_dir = /usr/lib/php5/20090626
On my own Version:
extension_dir = /opt/php5310/lib/php/extensions/no-debug-non-zts-20090626
(This folder doesn't even exist)
When I put this inside the php.ini:
extension_dir = /usr/lib/php5/20090626
It's working but is it the right way or just a creepy workaround?
And what about "--with-libdir=lib64" doesn't it belong to "extension_dir"?
On my System /usr/lib64 is a symlink to /usr/lib.
And last but not least my Repo-Version has a folder "/etc/php5/cgi/conf.d" with many ".ini" files e.g. "curl.ini", "gd.ini" and so on.
My Solution was:
"--with-config-file-scan-dir=/opt/php5310/conf.d
And then create the "conf.d" Folder and copy everthing from "/etc/php5/cgi/conf.d" to "/opt/php5310/conf.d" to be not dependent on the PHP Repo-Version.
Would this be a correct solution for multiple PHP-Versions or should it be a symlink or
"--with-config-file-scan-dir=/etc/php5/cgi/conf.d
Thank you for your help
Failing tests generally means failing functionality. Of course, for something as large as PHP you may never touch that functionality. It may be that your best bet here is to search for the names of the tests which failed to see if anyone has had the same issue (and how to fix it or disable the functionality), and to find the source of the tests in PHP and understand why they failed.
I built a pdf generator script for one of my clients and everything works properly. He then decided that he wanted me to create a thumbnail image from the PDF to display on another page, so I came across PHMagick and that seemed to do the trick.
The following code worked on my building server (iPage -- I think it's debian?), but now that I've moved it to his VPS, it is no longer working. FPDF has no trouble generating the pdf, so it is not a permissions issue.
Code:
require("phmagick/phmagick.php");
$pdf->Output("pdf.pdf");
$p = new phmagick('','pdf.png');
$p->debug = true;
$p->resize(800);
$p->acquireFrame("pdf.pdf");
This code returns the following error:
Error executing "convert "pdf.pdf"[0] "pdf.png"" return code: 127 command output :"sh: convert: command not found"
I have not changed any of the code since I moved it from the original server, and I just copied the entire site over, so why is PHMagick not working now? How do I get it to recognize convert.php in the plugins folder?
Just a note: I am only using PHMagick, not the whole of ImageMagick.
PHMagic appears to be using the command line convert command in background.
Most likely that command is simply not installed on the server.
PHMagic use the command line convert,composite etc... commands in background.
These commands are only available if ImageMagick is installed in your server.
In your previous server ImageMagick must have been installed.
Ipage sometimes do not pre install ImageMagick on their VPS servers. And you might not be able to install it your self ( through terminal login using ... yum install ImageMagick ) coz you will be prompt for root password.
To make sure the ImageMagick binaries are installed in ur server, in ur case the convert command,
type this command in the ssh terminal...
whereis convert
If the path to the convert command is not shown, it means you need to install ImageMagick.
You will have to open a support ticket and ask them to install it for you
As arkascha said, you'll need to install imagemagick. Try yum install imagemagick since you're running CentOS.
EDIT: May be a different capitalization: ImageMagick
i installed the xhprof profiling extension for php
Everything is fine except for the callgraph.php file, it returns:
failed to shell execute cmd=" dot -Tpng"
so i checked and the dot utility wasn't installed, so i installed it.
it appears to be running fine from the command line so i ran the scritp again, same error:
failed to shell execute cmd=" dot -Tpng"
the xhprof documentation states:
the callgraph image visualization ([View Callgraph]) feature relies on the presence of Graphviz "dot" utility in your path.
but i don't understand what i need to do now, specifically the "utility in your path" part
Any help appreciated, thanks guys
If you want graphing functions for xhprof run next command in terminal:
sudo apt-get install graphviz
When I enable error_reporting, I see there are some configuration variable are missing:
function xhprof_generate_image_by_dot($dot_script, $type) {
// get config => yep really dirty - but unobstrusive
global $_xhprof;
$errorFile = $_xhprof['dot_errfile'];
$tmpDirectory = $_xhprof['dot_tempdir'];
$dotBinary = $_xhprof['dot_binary'];
After add the following lines to xhprof_lib/config.php, it works
$_xhprof['dot_errfile'] = '/home/peniel/var/log/xhprof/error.log';
$_xhprof['dot_tempdir'] = '/home/peniel/var/log/xhprof';
$_xhprof['dot_binary'] = '/usr/bin/dot';
If you have installed graphviz this error also will occure because of the security restrictions. Some functions may be disabled. So, see your logs for some php warnings.
For example:
PHP Warning: proc_open() has been disabled for security reasons in /usr/share/php/xhprof_lib/utils/callgraph_utils.php on line 112
You need to configure php.ini or security.ini parameter "disable_functions".
Having the utility "in your path" means that it can be located by the environment variable PATH. This environment variables contains directories where the shell looks for binaries that you run without an explicit path.
Let's say the full path to dot is /opt/foo/bin/dot. Then you want to modify your PATH environment variable this way:
PATH=${PATH}:/opt/foo/bin
In my case this was caused simply because graphviz was not installed. You can check with which dot or locate graphviz on the command line.
steps for fast fix the issue if you have Graphviz and still getting error:
run "which dot"
/usr/local/bin/dot
open xhprof_lib/utils/callgraph_utils.php line 110
replace "dot" by "/usr/local/bin/dot" (or path you have)