×ðÁú¿­Ê±¹ÙÍøµÇ¼

laravel ÅжÏÊÇ·ñcli

laravel ÊÇÏÖ´ú php ¿ª·¢ÖеÄÈÈÃÅ¿ò¼ÜÖ®Ò» £¬ÆÕ±éÓ¦ÓÃÓÚ web Ó¦ÓóÌÐò¿ª·¢ºÍ api ¿ª·¢¡£ÔÚ laravel µÄÓ¦ÓóÌÐò¿ª·¢ÖÐ £¬ÎÒÃÇÐèÒª¾­³£ÅжϳÌÐòÊÇÔÚÏÂÁîÐÐģʽÏÂÔËÐÐÕÕ¾ÉÔÚ web ģʽÏÂÔËÐÐ £¬ÒÔ±ãÓ¦¶Ô²î±ðµÄÓ¦Óó¡¾°¡£

ÅÐ¶Ï Laravel ÊÇ·ñÔÚÏÂÁîÐÐģʽÏÂÔËÐÐÊǺܳ£¼ûµÄ²Ù×÷¡£ÀýÈç £¬ÎÒÃÇ¿ÉÄÜÐèÒªÔÚ CLI ÖÐÖ´ÐÐÍýÏëʹÃü¡¢´¦Àí´ó×ÚµÄÊý¾Ý¡¢ÌìÉúÎļþ¡¢¶ÔÊý¾Ý¿â¾ÙÐÐǨáãµÈµÈ¡£¶øÔÚ Web ģʽÏ £¬ÔòÐèÒª´¦Àí HTTP ÇëÇóºÍÏìÓ¦¡¢¾ÙÐÐÓû§Éí·ÝÈÏÖ¤¡¢Ê¹ÓÃÇ°¶Ë¿ò¼ÜµÈµÈ¡£Òò´Ë £¬×¼È·µÄÅÐ¶Ï Laravel ÕýÔÚÔËÐеÄģʽ £¬¹ØÓÚÎÒÃÇʵÏÖÔ½·¢ÓÐÓú͸ßЧµÄÓ¦ÓóÌÐòÖÁ¹ØÖ÷Òª¡£

ÔÚ Laravel ÖÐ £¬ÎÒÃÇ¿ÉÒÔͨ¹ý¼ì²é PHP ³£Á¿ PHP_SAPI À´ÅжÏÓ¦ÓóÌÐòµÄÔËÐÐģʽ¡£Õâ¸ö³£Á¿µÄÖµÌåÏÖÄ¿½ñ PHP ³ÌÐòÕýÔÚʹÓÃµÄ SAPI£¨Server Application Programming Interface £¬¼´Ð§ÀÍÆ÷¶ËÓ¦ÓóÌÐò±à³Ì½Ó¿Ú£©ÀàÐÍ¡£ÔÚÏÂÁîÐÐģʽÏ £¬PHP_SAPI ³£Á¿µÄֵͨ³£ÊÇ cli £¬¶øÔÚ Web Ó¦ÓóÌÐòÖÐ £¬ÔòÊÇ apache2handler »ò fpm-fcgi µÈ¡£

ÒÔÏÂÊÇʾÀý´úÂ룺

if (PHP_SAPI === 'cli') {
    // ÔÚÏÂÁîÐÐģʽÏÂÔËÐÐ
    echo 'Ä¿½ñÕýÔÚÔËÐÐÏÂÁîÐÐģʽ';
} else {
    // ÔÚ Web ģʽÏÂÔËÐÐ
    echo 'Ä¿½ñÕýÔÚÔËÐÐ Web ģʽ';
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëÖÐ £¬ÎÒÃÇʹÓà PHP_SAPI ³£Á¿À´ÅÐ¶Ï Laravel ÕýÔÚÄÄÖÖģʽÏÂÖ´ÐС£ÈôÊÇ PHP_SAPI µÄֵΪ cli £¬ÔòÅúעĿ½ñÓ¦ÓóÌÐòÔÚÏÂÁîÐÐģʽÏÂÔËÐÐ £¬²»È»¾ÍÊÇÔÚ Web ģʽÏÂÔËÐС£

³ýÁË¿ÉÒÔÔÚ´úÂëÖÐʹÓà PHP_SAPI ³£Á¿Íâ £¬ÎÒÃÇ»¹¿ÉÒÔͨ¹ý Laravel ÌṩµÄ App ¹¤¾ßÀ´ÅжÏÄ¿½ñ³ÌÐòµÄÔËÐÐģʽ¡£ÀýÈç £¬ÈôÊÇÎÒÃÇÏ£ÍûÔÚÓ¦ÓóÌÐòÖоÙÐвî±ðµÄÉèÖà £¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏ´úÂ룺

if (App::runningInConsole()) {
    // ÔÚÏÂÁîÐÐģʽÏÂÔËÐÐ
    echo 'Ä¿½ñÕýÔÚÔËÐÐÏÂÁîÐÐģʽ';
} else {
    // ÔÚ Web ģʽÏÂÔËÐÐ
    echo 'Ä¿½ñÕýÔÚÔËÐÐ Web ģʽ';
}

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖÐ £¬ÎÒÃÇʹÓÃÁË App ¹¤¾ßµÄ runningInConsole() ÒªÁì £¬¸ÃÒªÁ콫·µ»ØÒ»¸ö²¼¶ûÖµ¡£ÈôÊÇÄ¿½ñ Laravel Ó¦ÓóÌÐòÕýÔËÐÐÔÚ CLI ģʽÏ £¬Ôò¸ÃÒªÁ콫·µ»Ø true £¬²»È»½«·µ»Ø false¡£

³ýÁËʹÓà runningInConsole() ÒªÁì £¬App ¹¤¾ß»¹ÌṩÁËÐí¶à²î±ðµÄÒªÁì £¬¿ÉÒÔÈÃÎÒÃÇÇáËɵĻñÈ¡Ä¿½ñ³ÌÐòµÄÆäËûÊôÐÔºÍÇéÐαäÁ¿¡£ÀýÈç £¬ÎÒÃÇ¿ÉÒÔʹÓà environment() ÒªÁìÀ´»ñÈ¡Ä¿½ñÓ¦ÓóÌÐòµÄÇéÐαäÁ¿ £¬ÒÔ¾öÒéÔÚÄĸöÇéÐÎÖÐÔËÐÐÓ¦ÓóÌÐò¡£

×ܵÄÀ´Ëµ £¬Í¨¹ýÅÐ¶Ï Laravel ÊÇ·ñÔËÐÐÔÚ CLI ģʽÏ £¬¿ÉÒÔ×ÊÖúÎÒÃǸüºÃµØʹÓÿò¼ÜÌṩµÄ¹¦Ð§ºÍ×ÊÔ´¡£ÎÞÂÛÊÇÔÚ Web ģʽÏÂÕÕ¾ÉÔÚ CLI ģʽÏ £¬Laravel ÌṩÁËÖÚ¶àÓÐÓõŤ¾ßºÍÊÖÒÕ £¬¿ÉÒÔ×ÊÖúÎÒÃǸü¿ìËÙ¡¢¸ßЧµØ¿ª·¢Ó¦ÓóÌÐò¡£

ÒÔÉϾÍÊÇlaravel ÅжÏÊÇ·ñcliµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ