{"id":2141,"date":"2022-08-30T15:22:23","date_gmt":"2022-08-30T15:22:23","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/02\/problem-about-php-cli-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:22:23","modified_gmt":"2022-08-30T15:22:23","slug":"problem-about-php-cli-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-php-cli-collection-of-common-programming-errors\/","title":{"rendered":"problem about php-cli-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li>\n<img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/MGhY2.png?s=32&amp;g=1\" \/><br \/>\nhakre<br \/>\nphp ubuntu php-5.3 php-cli<br \/>\nI have written some code that I run remotely on a server via the php-cli and a particular method within this code (I&#8217;m unsure which method at the moment) is causing a segmentation fault.Apart from adding exit and echo calls down through my methods and manually pinpointing the bad bits &#8211; is there a way to catch the segmentation fault as it happens and find out what piece of the puzzle is crashing? Standard PHP errors are displayed through the error shutdown handlers, I&#8217;m unsure where to start wi<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/MGhY2.png?s=32&amp;g=1\" \/><br \/>\nhakre<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d3c6a7f974f5d687a394415a2122c6b6?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nroot<br \/>\nphp timezone php-cli<br \/>\nI use below codes to convert a 12hour UTC to a new timezone MySourceCodes: (part of my udp socket server codes) \/\/ $gps_time = &#8220;9:43:52&#8243;; $gps_time = $time_hour.&#8221;:&#8221;.$time_min.&#8221;:&#8221;.$time_sec; \/\/ $time_received = &#8220;01:45:04 2012-07-28&#8221;; $time_received = date(&#8216;H:i:s Y-m-d&#8217;);$utc = new DateTimeZone(&#8220;UTC&#8221;); $moscow = new DateTimeZone(&#8220;Europe\/Moscow&#8221;); \/\/Instantiate both AM and PM versions of your time $gps_time_am = new DateTime(&#8220;$gps_time AM&#8221;, $utc); $gps_time_pm = new DateTime(&#8220;$gps_time<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f01cdace86333c0718d8e1452013af2c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMatthias<br \/>\nmysql php php.ini php-cli<br \/>\nI try to run a PHP script from the command line, but get the following error:Call to undefined function mysql_connect()However, the mysql module is loaded:root \/var\/www\/scripts # php -m | grep mysql mysql mysqli pdo_mysqlI am on a Debian machine, so all modules are being loaded in their own .ini file:root \/var\/www\/scripts # php &#8211;ini Configuration File (php.ini) Path: \/etc\/php5\/cli Loaded Configuration File: \/etc\/php5\/cli\/php.ini Scan for additional .ini files in: \/etc\/php5\/cli\/conf.d Ad<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c032a0e8e40dd79b715420e4c5d03b00?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nmeagar<br \/>\nphp php-cli<br \/>\ni wanna using curl in php script and run it in command line mode.here is the script&lt;?php\/\/enable_dl(&#8220;php_curl.dll&#8221;);$ch = curl_init();$options=array(CURLOPT_URL=&gt;&#8221;http:\/\/test.com\/wp-content\/themes\/bluefocus\/images\/desc_img.jpg&#8221;,CURLOPT_BINARYTRANSFER=&gt;true,CURLOPT_VERBOSE=&gt;true);curl_setopt_array($ch,$options);$data = curl_exec($ch);$fp=fopen(&#8220;test.jpg&#8221;,&#8221;w&#8221;);fwrite($fp,$data);curl_close($ch); ?&gt;i run it in cmd with command php get.phpthe error message:D:\\project&gt;php get.phpFata<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/abea68a0d64977a82d9cfa4998fda01f?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMilo LaMar<br \/>\npowershell php-cli<br \/>\nThis question is regarding dollar signs &#8220;$&#8221; $ in Windows PowerShell ISE.I have PHP CLI and want to run one liner command scripts from the prompt in Windows PowerShell ISE.php -r &#8220;$foo = &#8216;foo&#8217;;&#8221;Just returns Parse error: parse error in Command line code on line 1 and I&#8217;ve narrowed it down to the pesky dollar sign which is significant in PowerShell. Can I escape it somehow?I also tried php -r &#8216;$foo = &#8220;foo&#8221;;&#8217; and get Notice: Use of undefined constant foo &#8211; assumed &#8216;foo&#8217; in Command line code on lin<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/MGhY2.png?s=32&amp;g=1\" \/><br \/>\nhakre<br \/>\nphp php-cli<br \/>\nI&#8217;m running a PHP script from CLI that user the DirectoryIterator::getExtension() method in PHP.The version of PHP I&#8217;m running under is 5.3.5, but I keep getting errors saying Fatal error: Call to undefined method DirectoryIterator::getExtension()The script works fine in my local dev machine running PHP 5.3.6, with no errors. However, the page for DirectoryIterator::getExtension() in the PHP man has no mention of version.Can anyone tell me what version I need to use this method?<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/py8eH.png?s=32&amp;g=1\" \/><br \/>\nBoaz<br \/>\nphp php-cli<br \/>\nWhy might the PHP -l switch not find errors in test.html.$ cat test.html &lt;?php error_reporting(E_ALL); echo &#8220;Hello, world!&#8221;;sdfsdfsdfsdf?&gt; $ php -dhtml_errors=0 -ddisplay_errors=On -l test.html No syntax errors detected in test.html $ php test.html Hello, world!PHP Notice: Use of undefined constant sdfsdfsdfsdf &#8211; assumed &#8216;sdfsdfsdfsdf&#8217; in test.html on line 7 $ Other types of errors are also not found, such as undefined functions, require_once() to nonexistant files, incorrect syntax in<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/MGhY2.png?s=32&amp;g=1\" \/><br \/>\nhakre<br \/>\nphp curl php-cli<br \/>\nCurl would not work on windows Command Prompt but it working fine on the browser (localhost)Error:C:\\wamp\\www\\site&gt;C:\\wamp\\bin\\php\\php5.3.0\\php.exe -f index.phpPHP Fatal error: Call to undefined function curl_init() in C:\\wamp\\www\\site\\index.php on line 111Fatal error: Call to undefined function curl_init() in C:\\wamp\\www\\site\\index.php on line 111Yes PHP Curl is enabled, like I said it work fine on the browser.<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/2f4504ee51cfbc6d8267ede414b33513?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nkonsolenfreddy<br \/>\nphp sqlite3 xml-parsing cli php-cli<br \/>\nHello I&#8217;m getting the following error Notice: Undefined offset: 1 in file.php on line 113line 113 is $publish_content=$matches2[1];This is my codeif(!preg_match(&#8216;\/\\&lt;content\\:encoded\\&gt;(?:\\&lt;\\!\\[CDATA\\[)?(.*?)(?:\\]\\]\\&gt;)?\\&lt;\\\/content\\:encoded\\&gt;\/si&#8217;,$item,$matches2)){for($i2=0;$i2&lt;count($info_tag_pairs);$i2++){if(preg_match(&#8216;\/&#8217;.custom_preg_quote($info_tag_pairs[$i2][0]).'(.*?)&#8217;.custom_preg_quote($info_tag_pairs[$i2][1]).&#8217;\/si&#8217;,$item,$matches2)){break;}}}$publish_content=$match<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/3c09250bd1e6c4618d8e469e7aa0468d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJeffrey04<br \/>\nosx-leopard macports warning php-cli<br \/>\nWhenever I run my php command line script, before the script actually outputs to the screen, php always returns a bunch of error messages as follows:PHP Warning: PHP Startup: Unable to load dynamic library &#8216;\/opt\/local\/lib\/php\/extensions\/no-debug-non-zts-20060613\/gd.so&#8217; &#8211; (null) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library &#8216;\/opt\/local\/lib\/php\/extensions\/no-debug-non-zts-20060613\/mbstring.so&#8217; &#8211; (null) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/07b2536f9431122cb50e54337956097c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSandeepan Nath<br \/>\nlinux php.ini php-extensions php-cli<br \/>\nI have two php.ini files &#8211; \/etc\/php.ini which loads in case of cli \/opt\/lampp\/etc\/php.ini which loads in case of browser.I am able to use PHP&#8217;s Mailparse extension after adding the line extension=mailparse.so in the \/opt\/lampp\/etc\/php.ini and restarting lampp. But I am not able to load the same in case of command line &#8211; getting PHP Fatal error: Call to undefined function mailparse_msg_create() in &#8230;mailparse_msg_create() is a part of the Mailparse extension.I tried by relogging with the user<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/43c71cd5c8ec34ca6a7946d1021fcc57?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJonathon Wisnoski<br \/>\nphp apache pdo crash php-cli<br \/>\nI have a really weird problem with a script I just wrote.It works perfectly using the CLI. Using the browser it crashes twice with the only error being:Error 103 (net::ERR_CONNECTION_ABORTED): Unknown error.Problem signature: Problem Event Name: APPCRASH Application Name: httpd.exe Application Version: 2.4.3.0 Application Timestamp: 502f70a3 Fault Module Name: StackHash_e136 Fault Module Version: 6.1.7601.17725 Fault Module Timestamp: 4ec49b8f Exception Code: c0000374 Exception Offset:<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d45a34439ae17a079045a23df5131b91?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSander Versluys<br \/>\nphp php-cli<br \/>\nI&#8217;ve installed various PHP packages to be able to use PHP with Apache but also in the commandline. From both I need to be able to connect to MySQL databases. Pretty simple right? That&#8217;s what I thought but with php-cli I receive following error:Fatal error: Call to undefined function mysql_pconnect()I have tried starting from scratch by removing all depending packages and configuration like this:sudo apt-get &#8211;purge remove php5 libapache2-mod-php5 php5-cli php5-mysqlThen I&#8217;ve run following comman<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9207dac1a08f23791251e6170b787646?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nmiddaparka<br \/>\nphp php-cli<br \/>\nI have a very limited access to server php configuration files . when I run some of my cron scripts which involves writing log files , I am getting a warning like this Comments starting with &#8216;#&#8217; are deprecated in \/etc\/php5\/cli\/conf.d\/ming.ini on line 1 in Unknown on line 0I googled a lot to find the reason , I got to know that we need to replace the &#8216;#&#8217; with &#8216;;&#8217; in ming.ini file . I informed this to my server admin to fix this below is the link where I got this fixHow to fix: PHP Deprecated er<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/MGhY2.png?s=32&amp;g=1\" \/><br \/>\nhakre<br \/>\nphp warnings php-extension php-cli<br \/>\nAfter recompiling php I get the following errors when I use php cli:PHP Warning: PHP Startup: imap: Unable to initialize module Module compiled with module API=20050922 PHP compiled with module API=20090626 These options need to matchin Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library &#8216;\/usr\/lib\/php\/modules\/ldap.so&#8217; &#8211; \/usr\/lib\/php\/modules\/ldap.so: undefined symbol: third_arg_force_ref in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library &#8216;\/u<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2014-01-02 12:09:17. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>hakre php ubuntu php-5.3 php-cli I have written some code that I run remotely on a server via the php-cli and a particular method within this code (I&#8217;m unsure which method at the moment) is causing a segmentation fault.Apart from adding exit and echo calls down through my methods and manually pinpointing the bad bits [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2141","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2141"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2141\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}