Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: Warning: array_map(): Argument #2 should be an array
    primarykey
    data
    text
    <p>I have a script that works perfect in ubuntu, recently I copied the exact same script to centos6 server and I'm getting the following error:</p> <pre><code>PHP Warning: array_map(): Argument #2 should be an array in /copy_scripts/classes/Vserver.class.php on line 245 </code></pre> <p>the code</p> <pre><code>/** * Get an array of open files * @param array $aExt * @return array of arrays ['views','size','path'] */ public function getOpenFiles($aExt=array()) { $aOpenFiles = self::GetList(self::$sLogOpenFiles); $aOpenFiles = array_map( create_function('$v', ' $v = trim($v); $aFile = preg_split("#[\t\s]+#",$v); $oFile = new VserverFile($aFile[2]); $oFile-&gt;setViews($aFile[0]); return $oFile;'), $aOpenFiles ); //echo "&lt;pre&gt;"; //print_r($aOpenFiles); return $aOpenFiles; } </code></pre> <p>Can it be the difference between php versions? </p> <p>centos:</p> <pre><code>PHP 5.3.3 (cli) (built: Jul 3 2012 16:53:21) </code></pre> <p>ubuntu</p> <pre><code>PHP 5.3.10-2 (cli) (built: Feb 20 2012 19:39:00) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies </code></pre> <p>what I've tried so far:</p> <ul> <li>changing setting in php.ini a restarting php.</li> </ul> <p>the complete code:</p> <pre><code>&lt;?php /** * * Global Video Server class * Singleton class * Has methods to manipulate files * @author kpoxas * */ class Vserver { static protected $oInstance=null; static protected $iTimeStart, $iTimeEnd; const FILE_NOEXIST = -2; const FILE_ZEROSIZE = -4; const FILE_DIFF = -8; /* * Path /var/www/HDD_PATH/ */ static public $sHDDPath = null; /* * Path /var/www/SSD_PATH/ */ static public $sSSDPath = null; /* * Folder same on every RAID.../FOLDER/... */ static public $sHTTPFolder = null; /* * Open Files Log */ static public $sLogOpenFiles = null; /* * Limit of Free space on SSD in percents */ static public $iSSDUsage = 90; /* * Limit of Free space on SSD in percents (not delete below) */ static public $iSSDDeleteUsage = 80; /* * Limit of Free space on SSD in bytes (not delete below) */ static public $iSSDDeleteUsageAbsolute = 5368709120; /* * Min views count of file to copy */ static public $iMinViews = 2; /* * Search within files older than $iDaysToDelete days */ static public $iDaysToDelete = 1; /* * Test Mode * File manipulations aren't executed * Only log mode */ static public $bTest = false; /* * Store openfiles.txt log */ static protected $sOpenFiles = null; /** * Äåñêðèïòîð áëîêèðóþùåãî ôàéëà * * @var string */ protected $oLockFile=null; /** * Singleton Object implementation * * @return VSERVER */ static public function getInstance() { if (isset(self::$oInstance) and (self::$oInstance instanceof self)) { return self::$oInstance; } else { self::$oInstance= new self(); return self::$oInstance; } } /** * Get Log content * @param string $sLogPath * @return string */ static public function GetLog($sLogPath) { if ($s = @file_get_contents($sLogPath)) { $s = trim($s); if (!empty($s)) { return $s; } } return false; } /** * Get Log content in list mode divided by EOL * @param string $sLogPath * @return array */ static public function GetList($sLogPath) { if ($sList = self::GetLog($sLogPath)) { return explode(PHP_EOL,trim($sList)); } } /** * Check if directory exists and chmod 775 * @param $directory */ static public function CheckDirectory($directory) { $directory = rtrim($directory, '/\\'); if (is_dir($directory)) @chmod($directory, 0775); else { if (!mkdir($directory, 0755, true)) { //self::AddError ('Directory does not exist', $directory); return false; } } } /** * Check if file exist * Check if file has zero size * @param string $filename */ static public function CheckFile($filename) { if (file_exists($filename) &amp;&amp; !is_file($filename)) { self::log("NO VALID FILEPATH: {$filename}"); return false; } else if(!file_exists($filename)) { self::log("FILE DOESN'T EXIST: {$filename}"); return self::FILE_NOEXIST; } else if(!filesize($filename)) { self::log("FILE ZEROSIZE: {$filename}"); return self::FILE_ZEROSIZE; } else return true; } /** * Check if file1 is identical to file2 * @param string $filename1 * @param string $filename2 */ static public function CheckIdentity($filename1, $filename2) { if (self::CheckFile($filename1)&gt;0 &amp;&amp; self::CheckFile($filename2)&gt;0) { if (filesize($filename1)===filesize($filename2)) { self::log("FILES: {$filename1} AND {$filename2} ARE IDENTICAL"); return true; } self::log("FILES: {$filename1} AND {$filename2} ARE DIFFERENT"); return false; } } /** * Copy file from $source to $dest * Make www-data owner * Make perms 755 */ static public function Copy($source, $dest = null) { self::log("COPY {$source} TO {$dest}"); if (self::$bTest) return true; self::CheckDirectory(dirname($dest)); // copy $sCmd = "cp -f '{$source}' '{$dest}'"; self::exec($sCmd); // chown $sCmdChown = "chown www-data:www-data '{$dest}'"; self::exec($sCmdChown); // chmod $sCmdChmod = "chmod 775 '{$dest}'"; self::exec($sCmdChmod); return true; } /** * Delete file */ static public function Delete($source) { self::log("DELETE {$source}"); if (self::$bTest) return true; // chmod $sCmdChmod = "rm '{$source}'"; self::exec($sCmdChmod); } /** * Get free space of catalog or storage in bytes * @param string $sDir */ static public function GetFreeSpace($sDir = '') { return disk_free_space($sDir); } /** * Get total space of catalog or storage in bytes * @param string $sDir */ static public function GetTotalSpace($sDir = '') { return disk_total_space($sDir); } /** * Get used space of catalog or storage in percents * @param string $sDir */ static public function GetUsage($sDir = '') { //$sCmd = "df -k {$sDir} | grep -Eo '[0-9]+%'"; //return intval(self::exec($sCmd)); return round(1-self::GetFreeSpace($sDir)/self::GetTotalSpace($sDir),4)*100; } /** * Exec command wrapper */ static public function exec($sCmd = null, &amp;$aVar=null) { if (empty($sCmd)) { return; } self::log($sCmd); return exec($sCmd, $aVar); } static public function log($sStr) { echo "{$sStr}&lt;br&gt;\n"; } /** * Get open files log * @return string */ static public function getOpenFilesContent() { if (self::$sOpenFiles === null) { self::$sOpenFiles = self::GetLog(self::$sLogOpenFiles); } return self::$sOpenFiles; } /** * Get an array of open files * @param array $aExt * @return array of arrays ['views','size','path'] */ public function getOpenFiles($aExt=array()) { $aOpenFiles = self::GetList(self::$sLogOpenFiles); $aOpenFiles = array_map( create_function('$v', ' $v = trim($v); $aFile = preg_split("#[\t\s]+#",$v); $oFile = new VserverFile($aFile[2]); $oFile-&gt;setViews($aFile[0]); return $oFile;'), $aOpenFiles ); //echo "&lt;pre&gt;"; //print_r($aOpenFiles); return $aOpenFiles; } public function getFileList($sDir=null, $aExt=array('flv','mp4'), $sGrep='') { if (!$sDir || empty($aExt)) return; $aCmdExt = "\( -name '*." .implode("' -o -name '*.",$aExt) ."' \)"; $sCmd = "find {$sDir} {$aCmdExt} -mmin +".self::$iDaysToDelete.""; // sort by date //$sCmd = "find {$sDir} {$aCmdExt} -printf '%T@ %p\n'| sort -k 1n | cut -d' ' -f2-"; if (!empty($sGrep)) { $sCmd.= " | {$sGrep}"; } self::exec($sCmd,$aFiles); return $aFiles; } /** * * Get list of storages */ public function getStorages() { $sCmd = "df -k | grep -Eo 'storage[0-9]+$'"; self::exec($sCmd,$aStorages); return $aStorages; } /** * * Get list of megastorages */ public function getMegaStorages() { $sCmd = "df -k | sort -k5 -r | grep -Eo 'megastorage[0-9]+$'"; self::exec($sCmd,$aStorages); return $aStorages; } /** * Copy opened files to SSD */ public function copyToSSD() { $this-&gt;setLock(__FUNCTION__.'.lock'); if($this-&gt;isLock()) { self::log("Process has already started."); return; } $iCopied = 0; $iIgnored = 0; $aOpenedFiles = $this-&gt;GetOpenFiles(); foreach ($aOpenedFiles as $oFile) { if (self::GetUsage(self::$sSSDPath) &lt; self::$iSSDUsage) { if ($oFile-&gt;getViews() &gt;=self::$iMinViews &amp;&amp; $oFile-&gt;synchronize()) $iCopied++; else $iIgnored++; } else { break; } } self::log("COPIED: {$iCopied}"); self::log("IGNORED: {$iIgnored}"); self::log("SSD USAGE: ".self::GetUsage(self::$sSSDPath)."%"); } /** * DELETE FROM SSD */ public function deleteFromSSD() { $this-&gt;setLock(__FUNCTION__.'.lock'); if($this-&gt;isLock()) { self::log("Process has already started."); return; } $iDeleted = 0; $iIgnored = 0; /* * Get megastorages sorted by usage desc, */ $aMegaStorages = $this-&gt;getMegaStorages(); foreach ($aMegaStorages as &amp;$sMegaStorage) { /* * Get files in current megastorage */ $aFileList = $this-&gt;getFileList('/'.$sMegaStorage); if (empty($aFileList)) { self::log("NO FILES FOUND in {$sMegaStorage}"); continue; } $aFileList = array_map( create_function('$v', ' $oFile = new VserverFile(trim($v)); return $oFile; '), $aFileList ); /* * Delete files until appropriate usage */ $iFreeSpace = self::GetFreeSpace('/'.$sMegaStorage); $iTotalSpace = self::GetTotalSpace('/'.$sMegaStorage); foreach ($aFileList as &amp;$oFile) { $iUsageCurrent = round(1-$iFreeSpace/$iTotalSpace,4)*100; self::Log($sMegaStorage." ".$iUsageCurrent."%"); if ($iUsageCurrent &gt; self::$iSSDDeleteUsage) { if (!$oFile-&gt;isOpened()) { $iFreeSpace += $oFile-&gt;getSize(); $oFile-&gt;synchronize(); $oFile-&gt;deleteFromSSD(); $iDeleted++; } else $iIgnored++; } else { break; } } } /* $aFileList = $this-&gt;getFileList(self::$sSSDPath); if (empty($aFileList)) { self::log("NO FILES FOUND"); return; } $aFileList = array_map( create_function('$v', ' $oFile = new VserverFile(trim($v)); return $oFile; '), $aFileList ); foreach ($aFileList as $oFile) { if (self::GetUsage(self::$sSSDPath) &gt; self::$iSSDDeleteUsage) { if (!$oFile-&gt;isOpened()) { $oFile-&gt;synchronize(); $oFile-&gt;deleteFromSSD(); $iDeleted++; } else $iIgnored++; } else { break; } } */ self::log("DELETED: {$iDeleted}"); self::log("IGNORED: {$iIgnored}"); self::log("SSD USAGE: ".self::GetUsage(self::$sSSDPath)."%"); } /** * DELETE FROM SSD * USING ABSOLUTE VALUE of $iSSDDeleteUsageAbsolute */ public function deleteFromSSDAbsolute() { $this-&gt;setLock(__FUNCTION__.'.lock'); if($this-&gt;isLock()) { self::log("Process has already started."); return; } $iDeleted = 0; $iIgnored = 0; /* * Get megastorages sorted by usage desc, */ $aMegaStorages = $this-&gt;getMegaStorages(); foreach ($aMegaStorages as &amp;$sMegaStorage) { /* * Get files in current megastorage */ $aFileList = $this-&gt;getFileList('/'.$sMegaStorage); if (empty($aFileList)) { self::log("NO FILES FOUND in {$sMegaStorage}"); continue; } $aFileList = array_map( create_function('$v', ' $oFile = new VserverFile(trim($v)); return $oFile; '), $aFileList ); /* * Delete files until appropriate usage */ $iFreeSpace = self::GetFreeSpace('/'.$sMegaStorage); foreach ($aFileList as &amp;$oFile) { self::Log($sMegaStorage." ".(round($iFreeSpace/1024/1024/1024,2))." G"); if ($iFreeSpace &lt; self::$iSSDDeleteUsageAbsolute) { if (!$oFile-&gt;isOpened()) { $iFreeSpace += $oFile-&gt;getSize(); $oFile-&gt;synchronize(); $oFile-&gt;deleteFromSSD(); $iDeleted++; } else $iIgnored++; } else { break; } } } self::log("DELETED: {$iDeleted}"); self::log("IGNORED: {$iIgnored}"); self::log("FREE SPACE: ".(round($iFreeSpace/1024/1024/1024,2))." G"); } /** * * Get Identical files on storages */ public function getIdentical() { $this-&gt;setLock(__FUNCTION__.'.lock'); if($this-&gt;isLock()) { self::log("Process has already started."); return; } $aStorages = $this-&gt;getStorages(); foreach ($aStorages as &amp;$sStorage) { $sDir = "/{$sStorage}/".self::$sHTTPFolder; $aList[$sStorage] = $this-&gt;getFileList($sDir,array('flv'), "grep -Eo '".self::$sHTTPFolder.".*$'"); } $iStorages = sizeof($aList); for ($i=0; $i&lt;$iStorages; $i++) { reset($aList); $sPrimaryStorage = key($aList); $aPrimaryFiles = array_shift($aList); foreach($aList as $sSecondaryStorage=&gt;&amp;$aSecondaryFiles) { self::log("{$sPrimaryStorage} &lt;-- {$sSecondaryStorage}"); //array of identical files $aIdentical = array_intersect($aPrimaryFiles, $aSecondaryFiles); if (!empty($aIdentical)) { // get sizes foreach ($aIdentical as $sFile) { $iPrimaryPath = "/{$sPrimaryStorage}/".$sFile; $iPrimarySize = filesize($iPrimaryPath); $iSecondaryPath = "/{$sSecondaryStorage}/".$sFile; $iSecondarySize = filesize($iSecondaryPath); self::log("| {$iPrimaryPath} &lt;-- {$iPrimarySize}"); self::log("| {$iSecondaryPath} &lt;-- {$iSecondarySize}"); // delete if sizes are identical if ($iPrimarySize == $iSecondarySize) self::Delete($iSecondaryPath); // if any have null size else if ($iPrimarySize * $iSecondarySize) continue; else if (filectime($iPrimarySize)&gt;filectime($iSecondaryPath)) self::Delete($iSecondaryPath); else if (filectime($iSecondaryPath)&gt;filectime($iPrimarySize)) self::Delete($iPrimarySize); } } } } //echo "&lt;pre&gt;"; //print_r(array_intersect($aPrimaryFiles, $aSecondaryFiles)); //echo "&lt;/pre&gt;"; } /** * Ñîçäàåò áëîêèðîâêó íà ïðîöåññ */ public function setLock($sLockFile=null) { if(!empty($sLockFile)) { $this-&gt;oLockFile=fopen($sLockFile,'a'); } } /** * Ïðîâåðÿåò óíèêàëüíîñòü ñîçäàâàåìîãî ïðîöåññà */ public function isLock() { return ($this-&gt;oLockFile &amp;&amp; !flock($this-&gt;oLockFile, LOCK_EX|LOCK_NB)); } /** * Ñíèìàåò áëîêèðîâêó íà ïîâòîðíûé ïðîöåññ */ public function unsetLock() { return ($this-&gt;oLockFile &amp;&amp; @flock($this-&gt;oLockFile, LOCK_UN)); } public function __construct() { self::$iTimeStart = microtime(true); } public function __destruct() { self::$iTimeEnd = microtime(true); $iTimeExecution = round(self::$iTimeEnd - self::$iTimeStart,3); $iUsageMem = memory_get_usage(true)/1024/1024; //Mb $iUsageMemPeak = memory_get_peak_usage(true)/1024/1024; //Mb self::log("Execution time: {$iTimeExecution} s"); self::log("Memory Usage: {$iUsageMem} Mb"); self::log("Memory Peak Usage: {$iUsageMemPeak} Mb"); $this-&gt;unsetLock(); } /** * Class autoloader * * @param unknown_type $sClassName */ public static function autoload($sClassName) { require_once("{$sClassName}.class.php"); } } spl_autoload_register(array('Vserver','autoload')); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload