Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a question regarding why via

php -q -f /home/user/public_html/file.php (this script contain a small script that create a file).

file.php content:

$csvFile = '';

function readCSV($csvFile){
    $file_handle = fopen($csvFile, 'r');
    while (!feof($file_handle) !== FALSE) {
        $line_of_text[] = fgetcsv($file_handle, 1024);
    return $line_of_text;

$csv = readCSV($csvFile);

$xml = new SimpleXMLElement('<data/>');

foreach ($csv as $_item){
            $itm = $xml->addChild('produs');
            $itm->addAttribute('city', $_item[0]);
            $itm->addAttribute('street', $_item[2]);
            $itm->addAttribute('number', $_item[3]);
            $itm->addAttribute('user', '0');

$dom = new DOMDocument();
$dom->formatOutput = true;
$formattedXML = $dom->saveXML();

$xmlFilePath = 'file.xml';
//i solved the issue with '/home/path/to/be/stored/'
$fp = fopen($xmlFilePath,'w+');
fwrite($fp, $formattedXML);

The issue is that on execute the command the file is not created, but on access on web via http it is created.

There is no error, it just say that the file has been created but is not.

Centos 6 - Minimal Server Nginx, PHP-FPM. User www-data and root, both does the same.

Any help is appreciated.

share|improve this question
Check your audit.log for relevant SELinux AVC denied messages. – Iain Jun 3 '14 at 6:46
You need to do error checking. Don't just blindly assume that functions will succeed. – Michael Hampton Jun 3 '14 at 10:01

most likely, this is a permission problem where when the process is executed via the php-fpm, it can write to the location in question, but when run by your user account, the location is not writable.

to see the full details of what is happening with the script, try running it under strace

strace php -q -f /home/user/public_html/file.php

share|improve this answer
well, the issue is that if i execute as it on shell, php -q /home/user/public_html/file.php i see that the file is created, but on put the command on a sh script it doesnt create :( – Dario Jun 3 '14 at 6:43
Can be an issue when the file name is specified without folder ? – Dario Jun 3 '14 at 6:47
there is no "put" command in bash/sh, unless you write the function yourself. edit the question and give more details in order to get more help. it is not clear what you are doing. – nandoP Jun 3 '14 at 6:47
the issue was that i have declared only the file name without folder, strange, because in other servers it work without declare the path. – Dario Jun 3 '14 at 7:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.